Patchwork [2,of,4,STABLE] ui: inline _write() into write() due to performance issue

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 24, 2019, 1:09 p.m.
Message ID <221e41f26c525e50032e.1548335367@mimosa>
Download mbox | patch
Permalink /patch/37956/
State Accepted
Headers show

Comments

Yuya Nishihara - Jan. 24, 2019, 1:09 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1548333288 -32400
#      Thu Jan 24 21:34:48 2019 +0900
# Branch stable
# Node ID 221e41f26c525e50032eca31664cc94c814a3128
# Parent  ea3f96b253cb2b3f42a224bdd71ff04157b2c33d
ui: inline _write() into write() due to performance issue

I'll remove redundant conditions later in this series.

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -999,12 +999,23 @@  class ui(object):
         "cmdname.type" is recommended. For example, status issues
         a label of "status.modified" for modified files.
         '''
-        self._write(self._fout, *args, **opts)
+        dest = self._fout
+
+        # inlined _write() for speed
+        if self._isbuffered(dest):
+            label = opts.get(r'label', '')
+            if label and self._bufferapplylabels:
+                self._buffers[-1].extend(self.label(a, label) for a in args)
+            else:
+                self._buffers[-1].extend(args)
+        else:
+            self._writenobuf(dest, *args, **opts)
 
     def write_err(self, *args, **opts):
         self._write(self._ferr, *args, **opts)
 
     def _write(self, dest, *args, **opts):
+        # update write() as well if you touch this code
         if self._isbuffered(dest):
             label = opts.get(r'label', '')
             if label and self._bufferapplylabels: