revlog: avoid an expensive string copy
authorBryan O'Sullivan <bryano@fb.com>
Thu, 12 Apr 2012 20:26:33 -0700
changeset 16423 a150923b49ba
parent 16422 c0b5bab3fb11
child 16424 ff63d71ac8ab
revlog: avoid an expensive string copy This showed up in a statprof profile of "hg svn rebuildmeta", which is read-intensive on the changelog. This two-line patch improved the performance of that command by 10%.
mercurial/revlog.py
--- a/mercurial/revlog.py	Fri Apr 13 22:55:46 2012 -0500
+++ b/mercurial/revlog.py	Thu Apr 12 20:26:33 2012 -0700
@@ -818,7 +818,7 @@
         df.close()
         self._addchunk(offset, d)
         if readahead > length:
-            return d[:length]
+            return util.buffer(d, 0, length)
         return d
 
     def _getchunk(self, offset, length):
@@ -831,7 +831,7 @@
         if cachestart >= 0 and cacheend <= l:
             if cachestart == 0 and cacheend == l:
                 return d # avoid a copy
-            return d[cachestart:cacheend]
+            return util.buffer(d, cachestart, cacheend - cachestart)
 
         return self._loadchunk(offset, length)
 
@@ -864,7 +864,7 @@
     def revdiff(self, rev1, rev2):
         """return or calculate a delta between two revisions"""
         if rev1 != nullrev and self.deltaparent(rev2) == rev1:
-            return self._chunk(rev2)
+            return str(self._chunk(rev2))
 
         return mdiff.textdiff(self.revision(self.node(rev1)),
                               self.revision(self.node(rev2)))
@@ -921,7 +921,7 @@
 
         self._chunkraw(base, rev)
         if text is None:
-            text = self._chunkbase(base)
+            text = str(self._chunkbase(base))
 
         bins = [self._chunk(r) for r in chain]
         text = mdiff.patches(text, bins)