Read about our upcoming Code of Conduct on this issue

Commit 2800ffe6 authored by Gregory Szorc's avatar Gregory Szorc
Browse files

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.
parent c57ebef70f6f
......@@ -424,10 +424,7 @@ class colorui(uimod.ui):
return super(colorui, self).popbuffer(labeled)
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 @@ class colorui(uimod.ui):
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)
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)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment