# HG changeset patch # User Gregory Szorc # Date 1448230722 28800 # 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 -r c57ebef70f6f -r 717b75ae5bb0 hgext/color.py --- 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)