[PATCH 3 of 5] color: evaluate labels at write time
Gregory Szorc
gregory.szorc at gmail.com
Tue Nov 24 15:11:40 CST 2015
# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1448230722 28800
# Sun Nov 22 14:18:42 2015 -0800
# Node ID 0815d0aba10f81ab688681254471e61b51aee064
# Parent 2a6c2d5021c0be9d60b6e77fd1ba3e796e59a09b
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.
diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -423,21 +423,22 @@ class colorui(uimod.ui):
if self._colormode is None:
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):
if self._colormode is None:
return super(colorui, self).write(*args, **opts)
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)
else:
More information about the Mercurial-devel
mailing list