Patchwork [7,of,7,hglib] hglib: optimize bytes conversion and concatentation (issue4520)

login
register
mail settings
Submitter Brett Cannon
Date March 26, 2015, 12:40 a.m.
Message ID <5fd7c9d103ee0424e10a.1427330401@bcannon-macbookpro2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/8284/
State Accepted
Headers show

Comments

Brett Cannon - March 26, 2015, 12:40 a.m.
# HG changeset patch
# User Brett Cannon <brett@python.org>
# Date 1427330246 14400
#      Wed Mar 25 20:37:26 2015 -0400
# Node ID 5fd7c9d103ee0424e10a9e2d4cc08c7b733a2e71
# Parent  580123ac44cc97d4ad2cc7b7a9c874be5e473d30
hglib: optimize bytes conversion and concatentation (issue4520)

Patch

diff -r 580123ac44cc -r 5fd7c9d103ee hglib/context.py
--- a/hglib/context.py	Wed Mar 25 20:27:34 2015 -0400
+++ b/hglib/context.py	Wed Mar 25 20:37:26 2015 -0400
@@ -1,7 +1,7 @@ 
 import hglib.client  # Circular dependency.
 from hglib import util, templates
 from hglib.error import CommandError
-from hglib.util import b, strtobytes, integertypes
+from hglib.util import b, strtobytes, integertypes, bytesjoin
 
 _nullcset = [b('-1'), b('0000000000000000000000000000000000000000'), b(''),
              b(''), b(''), b(''), b('')]
@@ -20,7 +20,7 @@ 
             cset = _nullcset
         else:
             if isinstance(changeid, integertypes):
-                changeid = b('rev(') + strtobytes(changeid) + b(')')
+                changeid = bytesjoin(b('rev('), strtobytes(changeid), b(')'))
 
             notfound = False
             try:
@@ -219,15 +219,16 @@ 
 
     def children(self):
         """return contexts for each child changeset"""
-        for c in self._repo.log(b('children(') + self._node + b(')')):
+        for c in self._repo.log(bytesjoin(b('children('), self._node, b(')'))):
             yield changectx(self._repo, c)
 
     def ancestors(self):
-        for a in self._repo.log(b('ancestors(') + self._node + b(')')):
+        for a in self._repo.log(bytesjoin(b('ancestors('), self._node, b(')'))):
             yield changectx(self._repo, a)
 
     def descendants(self):
-        for d in self._repo.log(b('descendants(') + self._node + b(')')):
+        descendant = bytesjoin(b('descendants('), self._node, b(')'))
+        for d in self._repo.log(descendant):
             yield changectx(self._repo, d)
 
     def ancestor(self, c2):
@@ -235,4 +236,4 @@ 
         return the ancestor context of self and c2
         """
         return changectx(self._repo,
-                         b('ancestor(') + self + b(', ') + c2 + b(')'))
+                         bytesjoin(b('ancestor('), self, b(', '), c2, b(')')))
diff -r 580123ac44cc -r 5fd7c9d103ee hglib/util.py
--- a/hglib/util.py	Wed Mar 25 20:27:34 2015 -0400
+++ b/hglib/util.py	Wed Mar 25 20:37:26 2015 -0400
@@ -16,14 +16,15 @@ 
     from itertools import izip
     integertypes = (long, int)
 
-    def b(s):
-        """Encode the string as bytes."""
-        return s
+    b = str
 
 def strtobytes(s):
     """Return the bytes of the string representation of an object."""
     return str(s).encode('latin-1')
 
+def bytesjoin(*args):
+    return b('').join(args)
+
 def grouper(n, iterable):
     ''' list(grouper(2, range(4))) -> [(0, 1), (2, 3)] '''
     args = [iter(iterable)] * n