color: evaluate labels at write time
Previously, we stored 2-tuples of text and label in a list and then
evaluated the labels when the buffer was popped. After this patch,
we evaluate the labels at write time and do a simple join when the
buffer is popped.
This patch appears to have no impact on performance, despite creating
fewer 2-tuples and having fewer strings hanging around in memory.
--- a/hgext/color.py Sun Nov 22 14:13:25 2015 -0800
+++ b/hgext/color.py Sun Nov 22 14:18:42 2015 -0800
@@ -424,10 +424,7 @@
return super(colorui, self).popbuffer(labeled)
self._bufferstates.pop()
- if labeled:
- return ''.join(self.label(a, label) for a, label
- in self._buffers.pop())
- return ''.join(a for a, label in self._buffers.pop())
+ return ''.join(self._buffers.pop())
_colormode = 'ansi'
def write(self, *args, **opts):
@@ -436,7 +433,11 @@
label = opts.get('label', '')
if self._buffers:
- self._buffers[-1].extend([(str(a), label) for a in args])
+ if self._bufferapplylabels:
+ self._buffers[-1].extend(self.label(str(a), label)
+ for a in args)
+ else:
+ self._buffers[-1].extend(str(a) for a in args)
elif self._colormode == 'win32':
for a in args:
win32print(a, super(colorui, self).write, **opts)