Mercurial > hg
changeset 2427:150cde10ea21
dirstate.read: make 15% faster.
time to read dirstate for my kernel repo goes from 0.22s to 0.18s.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Mon, 12 Jun 2006 22:09:50 -0700 |
parents | fb942bc15ef9 |
children | 42b8a1ff46cf |
files | mercurial/dirstate.py |
diffstat | 1 files changed, 22 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/dirstate.py Mon Jun 12 09:36:44 2006 -0700 +++ b/mercurial/dirstate.py Mon Jun 12 22:09:50 2006 -0700 @@ -155,31 +155,41 @@ if self.map is None: self.read() - def read(self): - self.map = {} - self.pl = [nullid, nullid] - try: - st = self.opener("dirstate").read() - if not st: return - except: return - + def parse(self, st): self.pl = [st[:20], st[20: 40]] + # deref fields so they will be local in loop + map = self.map + copies = self.copies + format = self.format + unpack = struct.unpack + pos = 40 - e_size = struct.calcsize(self.format) + e_size = struct.calcsize(format) + while pos < len(st): newpos = pos + e_size - e = struct.unpack(self.format, st[pos:newpos]) + e = unpack(format, st[pos:newpos]) l = e[4] pos = newpos newpos = pos + l f = st[pos:newpos] if '\0' in f: f, c = f.split('\0') - self.copies[f] = c - self.map[f] = e[:4] + copies[f] = c + map[f] = e[:4] pos = newpos + def read(self): + self.map = {} + self.pl = [nullid, nullid] + try: + st = self.opener("dirstate").read() + if st: + self.parse(st) + except IOError, err: + if err.errno != errno.ENOENT: raise + def copy(self, source, dest): self.lazyread() self.markdirty()