# HG changeset patch # User Matt Mackall # Date 1185241448 18000 # Node ID e45fc5d0379879a37b2ef728461049701b255efa # Parent d36310dd51d7045a2cbfa78cd6b94fce1d9eb741 manifest: speed up creation of the manifestdict - fold iteration and rawset into parse - avoid creating extra new strings with [:] where possible - speed up node.bin diff --git a/mercurial/manifest.py b/mercurial/manifest.py --- a/mercurial/manifest.py +++ b/mercurial/manifest.py @@ -23,10 +23,6 @@ class manifestdict(dict): def linkf(self, f): "test for symlink in manifest flags" return "l" in self.flags(f) - def rawset(self, f, entry): - self[f] = bin(entry[:40]) - fl = entry[40:-1] - if fl: self._flags[f] = fl def set(self, f, execf=False, linkf=False): if linkf: self._flags[f] = "l" elif execf: self._flags[f] = "x" @@ -40,16 +36,19 @@ class manifest(revlog): self.listcache = None revlog.__init__(self, opener, "00manifest.i") - def parselines(self, lines): - for l in lines.splitlines(1): - yield l.split('\0') + def parse(self, lines): + mfdict = manifestdict() + for l in lines.splitlines(): + f, n = l.split('\0') + if len(n) > 40: + mfdict._flags[f] = n[40:] + mfdict[f] = bin(n[:40]) + else: + mfdict[f] = bin(n) + return mfdict def readdelta(self, node): - delta = mdiff.patchtext(self.delta(node)) - deltamap = manifestdict() - for f, n in self.parselines(delta): - deltamap.rawset(f, n) - return deltamap + return self.parse(mdiff.patchtext(self.delta(node))) def read(self, node): if node == nullid: return manifestdict() # don't upset local cache @@ -57,9 +56,7 @@ class manifest(revlog): return self.mapcache[1] text = self.revision(node) self.listcache = array.array('c', text) - mapping = manifestdict() - for f, n in self.parselines(text): - mapping.rawset(f, n) + mapping = self.parse(text) self.mapcache = (node, mapping) return mapping diff --git a/mercurial/node.py b/mercurial/node.py --- a/mercurial/node.py +++ b/mercurial/node.py @@ -12,11 +12,9 @@ import binascii nullrev = -1 nullid = "\0" * 20 -def hex(node): - return binascii.hexlify(node) - -def bin(node): - return binascii.unhexlify(node) +# This ugly style has a noticeable effect in manifest parsing +hex = binascii.hexlify +bin = binascii.unhexlify def short(node): return hex(node[:6])