# HG changeset patch # User Pierre-Yves David # Date 1489273149 28800 # Node ID e7ad31804da82b826c292c52120c50597596cdc0 # Parent ed140544e7fdc545c4a265ccf9cece90d5eaad33 rangeobshash: minor cleanup of the obshash code We achieved minor speedup by delaying the hashing until we know it is needed. diff -r ed140544e7fd -r e7ad31804da8 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')