rangeobshash: minor cleanup of the obshash code
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Sat, 11 Mar 2017 14:59:09 -0800
changeset 2093 e7ad31804da8
parent 2092 ed140544e7fd
child 2094 e906723ab99f
rangeobshash: minor cleanup of the obshash code We achieved minor speedup by delaying the hashing until we know it is needed.
hgext3rd/evolve/obsdiscovery.py
--- a/hgext3rd/evolve/obsdiscovery.py	Sat Mar 11 14:46:27 2017 -0800
+++ b/hgext3rd/evolve/obsdiscovery.py	Sat Mar 11 14:59:09 2017 -0800
@@ -616,34 +616,34 @@
     @util.propertycache
     def obshash(self):
         cache = self._repo.obsstore.rangeobshashcache
-        obshash = cache.get(self._id)
+        obshash = cache.get(self)
         if obshash is not None:
             return obshash
-        sha = hashlib.sha1()
-        count = 0
+        pieces = []
+        nullid = node.nullid
         if len(self) == 1:
             tmarkers = self._repo.obsstore.relevantmarkers([self.node])
-            bmarkers = []
+            pieces = []
             for m in tmarkers:
                 mbin = obsolete._fm1encodeonemarker(m)
-                bmarkers.append(mbin)
-            bmarkers.sort()
-            for m in bmarkers:
-                count += 1
-                sha.update(m)
+                pieces.append(mbin)
+            pieces.sort()
         else:
             for subrange in self.subranges():
                 obshash = subrange.obshash
-                if obshash != node.nullid:
-                    count += 1
-                    sha.update(obshash)
+                if obshash != nullid:
+                    pieces.append(obshash)
 
+        sha = hashlib.sha1()
         # note: if there is only one subrange with actual data, we'll just
         # reuse the same hash.
-        if not count:
+        if not pieces:
             obshash = node.nullid
-        elif count != 1 or obshash is None:
-            obshash = cache[self._id] = sha.digest()
+        elif len(pieces) != 1 or obshash is None:
+            sha = hashlib.sha1()
+            for p in pieces:
+                sha.update(p)
+            obshash = cache[self] = sha.digest()
         return obshash
 
 @eh.wrapfunction(obsolete.obsstore, '_addmarkers')