Patchwork [4,of,6] ui: simply concatenate messages before applying color labels

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 4, 2018, 12:55 p.m.
Message ID <a06a7817128665f6d8eb.1541336124@mimosa>
Download mbox | patch
Permalink /patch/36359/
State Accepted
Headers show

Comments

Yuya Nishihara - Nov. 4, 2018, 12:55 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1541234525 -32400
#      Sat Nov 03 17:42:05 2018 +0900
# Node ID a06a7817128665f6d8eb398230b8321e8caf0c4f
# Parent  5825c9e9abddbe48b4635178eaac5571e587f9c3
ui: simply concatenate messages before applying color labels

This should be cheaper in space than applying labels for each message.

Patch

diff --git a/mercurial/color.py b/mercurial/color.py
--- a/mercurial/color.py
+++ b/mercurial/color.py
@@ -487,11 +487,7 @@  if pycompat.iswindows:
             ansire = re.compile(b'\033\[([^m]*)m([^\033]*)(.*)',
                                 re.MULTILINE | re.DOTALL)
 
-    def win32print(ui, writefunc, *msgs, **opts):
-        for text in msgs:
-            _win32print(ui, text, writefunc, **opts)
-
-    def _win32print(ui, text, writefunc, **opts):
+    def win32print(ui, writefunc, text, **opts):
         label = opts.get(r'label', '')
         attr = origattr
 
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -951,16 +951,16 @@  class ui(object):
 
     def _writenobuf(self, write, *args, **opts):
         self._progclear()
+        msg = b''.join(args)
         if self._colormode == 'win32':
             # windows color printing is its own can of crab, defer to
             # the color module and that is it.
-            color.win32print(self, write, *args, **opts)
+            color.win32print(self, write, msg, **opts)
         else:
-            msgs = args
             if self._colormode is not None:
                 label = opts.get(r'label', '')
-                msgs = [self.label(a, label) for a in args]
-            write(b''.join(msgs))
+                msg = self.label(msg, label)
+            write(msg)
 
     def _write(self, data):
         # opencode timeblockedsection because this is a critical path