comparison mercurial/manifest.py @ 4995:e45fc5d03798

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
author Matt Mackall <mpm@selenic.com>
date Mon, 23 Jul 2007 20:44:08 -0500
parents 63b9d2deed48
children 8d00788ca578
comparison
equal deleted inserted replaced
4994:d36310dd51d7 4995:e45fc5d03798
21 "test for executable in manifest flags" 21 "test for executable in manifest flags"
22 return "x" in self.flags(f) 22 return "x" in self.flags(f)
23 def linkf(self, f): 23 def linkf(self, f):
24 "test for symlink in manifest flags" 24 "test for symlink in manifest flags"
25 return "l" in self.flags(f) 25 return "l" in self.flags(f)
26 def rawset(self, f, entry):
27 self[f] = bin(entry[:40])
28 fl = entry[40:-1]
29 if fl: self._flags[f] = fl
30 def set(self, f, execf=False, linkf=False): 26 def set(self, f, execf=False, linkf=False):
31 if linkf: self._flags[f] = "l" 27 if linkf: self._flags[f] = "l"
32 elif execf: self._flags[f] = "x" 28 elif execf: self._flags[f] = "x"
33 else: self._flags[f] = "" 29 else: self._flags[f] = ""
34 def copy(self): 30 def copy(self):
38 def __init__(self, opener): 34 def __init__(self, opener):
39 self.mapcache = None 35 self.mapcache = None
40 self.listcache = None 36 self.listcache = None
41 revlog.__init__(self, opener, "00manifest.i") 37 revlog.__init__(self, opener, "00manifest.i")
42 38
43 def parselines(self, lines): 39 def parse(self, lines):
44 for l in lines.splitlines(1): 40 mfdict = manifestdict()
45 yield l.split('\0') 41 for l in lines.splitlines():
42 f, n = l.split('\0')
43 if len(n) > 40:
44 mfdict._flags[f] = n[40:]
45 mfdict[f] = bin(n[:40])
46 else:
47 mfdict[f] = bin(n)
48 return mfdict
46 49
47 def readdelta(self, node): 50 def readdelta(self, node):
48 delta = mdiff.patchtext(self.delta(node)) 51 return self.parse(mdiff.patchtext(self.delta(node)))
49 deltamap = manifestdict()
50 for f, n in self.parselines(delta):
51 deltamap.rawset(f, n)
52 return deltamap
53 52
54 def read(self, node): 53 def read(self, node):
55 if node == nullid: return manifestdict() # don't upset local cache 54 if node == nullid: return manifestdict() # don't upset local cache
56 if self.mapcache and self.mapcache[0] == node: 55 if self.mapcache and self.mapcache[0] == node:
57 return self.mapcache[1] 56 return self.mapcache[1]
58 text = self.revision(node) 57 text = self.revision(node)
59 self.listcache = array.array('c', text) 58 self.listcache = array.array('c', text)
60 mapping = manifestdict() 59 mapping = self.parse(text)
61 for f, n in self.parselines(text):
62 mapping.rawset(f, n)
63 self.mapcache = (node, mapping) 60 self.mapcache = (node, mapping)
64 return mapping 61 return mapping
65 62
66 def _search(self, m, s, lo=0, hi=None): 63 def _search(self, m, s, lo=0, hi=None):
67 '''return a tuple (start, end) that says where to find s within m. 64 '''return a tuple (start, end) that says where to find s within m.