# HG changeset patch # User Gregory Szorc # Date 2015-11-22 22:18:42 # Node ID 717b75ae5bb0c7f5b0354388d7422cdb988cd4b2 # Parent c57ebef70f6fdaf691d245381178adb6f73c09bd 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 @@ -424,10 +424,7 @@ class colorui(uimod.ui): 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 @@ 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) + 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)