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
This commit is contained in:
Matt Mackall 2007-07-23 20:44:08 -05:00
parent dd01d60440
commit f7f7d43737
2 changed files with 15 additions and 20 deletions

View File

@ -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

View File

@ -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])