changeset 16423:a150923b49ba

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%.
author Bryan O'Sullivan <bryano@fb.com>
date Thu, 12 Apr 2012 20:26:33 -0700
parents c0b5bab3fb11
children ff63d71ac8ab
files mercurial/revlog.py
diffstat 1 files changed, 4 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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)