Mercurial > hg
changeset 2080:1cbb14c048cb
Reduce index memory usage by storing the bare string instead of tuples
Storing the tuple returned by struct.unpack significantly increases
the memory required to store the entire index in ram. This patch
uses struct.unpack on demand instead.
author | mason@suse.com |
---|---|
date | Tue, 04 Apr 2006 19:00:40 -0400 |
parents | ee96ca273f32 |
children | 416d8b2a75b8 |
files | mercurial/revlog.py |
diffstat | 1 files changed, 13 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/revlog.py Tue Apr 04 16:47:12 2006 -0400 +++ b/mercurial/revlog.py Tue Apr 04 19:00:40 2006 -0400 @@ -135,9 +135,9 @@ for x in xrange(lend): if self.index[i + x] == None: b = data[off : off + self.s] - e = struct.unpack(self.format, b) - self.index[i + x] = e - self.map[e[-1]] = i + x + self.index[i + x] = b + n = b[self.shaoffset:self.shaoffset + 20] + self.map[n] = i + x off += self.s def findnode(self, node): @@ -218,7 +218,10 @@ self.p.loadindex(pos) return self.p.index[pos] def __getitem__(self, pos): - return self.p.index[pos] or self.load(pos) + ret = self.p.index[pos] or self.load(pos) + if isinstance(ret, str): + ret = struct.unpack(self.p.indexformat, ret) + return ret def __setitem__(self, pos, item): self.p.index[pos] = item def __delitem__(self, pos): @@ -242,11 +245,13 @@ def __iter__(self): yield nullid for i in xrange(self.p.l): - try: - yield self.p.index[i][-1] - except: + ret = self.p.index[i] + if not ret: self.p.loadindex(i) - yield self.p.index[i][-1] + ret = self.p.index[i] + if isinstance(ret, str): + ret = struct.unpack(self.p.indexformat, ret) + yield ret[-1] def __getitem__(self, key): try: return self.p.map[key]