Mercurial > evolve
changeset 2093:e7ad31804da8
rangeobshash: minor cleanup of the obshash code
We achieved minor speedup by delaying the hashing until we know it is needed.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Sat, 11 Mar 2017 14:59:09 -0800 |
parents | ed140544e7fd |
children | e906723ab99f |
files | hgext3rd/evolve/obsdiscovery.py |
diffstat | 1 files changed, 15 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- 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')