changeset 4993:4205f626dc05

lazyindex: speed up __getitem__ This function is fairly performance sensitive, so we make a couple ugly tweaks: - keep all entries packed so we needn't test entry types - fold index lookup/load into unpack call to eliminate local variable setting
author Matt Mackall <mpm@selenic.com>
date Mon, 23 Jul 2007 20:44:08 -0500
parents 0a676643687b
children d36310dd51d7
files mercurial/revlog.py
diffstat 1 files changed, 5 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlog.py	Mon Jul 23 20:44:08 2007 -0500
+++ b/mercurial/revlog.py	Mon Jul 23 20:44:08 2007 -0500
@@ -236,18 +236,16 @@
         self.p.loadindex(pos)
         return self.p.index[pos]
     def __getitem__(self, pos):
-        ret = self.p.index[pos] or self.load(pos)
-        if isinstance(ret, str):
-            ret = struct.unpack(indexformatng, ret)
-        return ret
+        return struct.unpack(indexformatng,
+                             self.p.index[pos] or self.load(pos))
     def __setitem__(self, pos, item):
-        self.p.index[pos] = item
+        self.p.index[pos] = struct.pack(indexformatng, *item)
     def __delitem__(self, pos):
         del self.p.index[pos]
     def insert(self, pos, e):
-        self.p.index.insert(pos, e)
+        self.p.index.insert(pos, struct.pack(indexformatng, *e))
     def append(self, e):
-        self.p.index.append(e)
+        self.p.index.append(struct.pack(indexformatng, *e))
 
 class lazymap(object):
     """a lazy version of the node map"""