# HG changeset patch # User Nicolas Dumazet # Date 1278326994 -32400 # Node ID ab9fa7a85dd9580384bd15faf9df281b95161be7 # Parent 2370e270a29a34c2e7f9fb22270bc6d6a6da55c8 filelog: cmp: don't read data if hashes are identical (issue2273) filelog.renamed() is an expensive call as it reads the filelog if p1 == nullid. It's more efficient to first compute the hash, and to bail early if the computed hash is the same as the stored nodeid. 'samehashes' variable is not strictly necessary, but helps for comprehension. diff -r 2370e270a29a -r ab9fa7a85dd9 mercurial/filelog.py --- a/mercurial/filelog.py Mon Jul 05 18:43:46 2010 +0900 +++ b/mercurial/filelog.py Mon Jul 05 19:49:54 2010 +0900 @@ -62,9 +62,18 @@ returns True if text is different than what is stored. """ - # for renames, we have to go the slow way - if text.startswith('\1\n') or self.renamed(node): + t = text + if text.startswith('\1\n'): + t = '\1\n\1\n' + text + + samehashes = not revlog.revlog.cmp(self, node, t) + if samehashes: + return False + + # renaming a file produces a different hash, even if the data + # remains unchanged. Check if it's the case (slow): + if self.renamed(node): t2 = self.read(node) return t2 != text - return revlog.revlog.cmp(self, node, text) + return True