[PATCH 4 of 4 STABLE] ui: remove unreachable branches and function calls from write() (issue6059)

Yuya Nishihara yuya at tcha.org
Thu Jan 24 08:09:29 EST 2019


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1548333482 -32400
#      Thu Jan 24 21:38:02 2019 +0900
# Branch stable
# Node ID 21e8987a6026d7cec613aa241a78e2926b878c5b
# Parent  c49dcc53a5d254c27b73838d97771bd26ed5fd45
ui: remove unreachable branches and function calls from write() (issue6059)

This is at least faster than ui.write() of 4.8.2.

  $ HGRCPATH=/dev/null hg files -R mozilla-central --time >/dev/null
  4.8.2:  time: real 2.340 secs (user 2.310+0.000 sys 0.020+0.000)
  4.9rc0: time: real 2.580 secs (user 2.550+0.000 sys 0.020+0.000)
  this:   time: real 2.230 secs (user 2.210+0.000 sys 0.020+0.000)

Maybe the formatter should own a resolved write() function because it will
just call dest.write(msg) most of the time, but that would be too much for
stable.

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -1002,7 +1002,7 @@ class ui(object):
         dest = self._fout
 
         # inlined _write() for speed
-        if self._isbuffered(dest):
+        if self._buffers:
             label = opts.get(r'label', '')
             if label and self._bufferapplylabels:
                 self._buffers[-1].extend(self.label(a, label) for a in args)
@@ -1017,13 +1017,7 @@ class ui(object):
         # opencode timeblockedsection because this is a critical path
         starttime = util.timer()
         try:
-            if dest is self._ferr and not getattr(self._fout, 'closed', False):
-                self._fout.flush()
-            if getattr(dest, 'structured', False):
-                # channel for machine-readable output with metadata, where
-                # no extra colorization is necessary.
-                dest.write(msg, **opts)
-            elif self._colormode == 'win32':
+            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, dest.write, msg, **opts)
@@ -1032,15 +1026,7 @@ class ui(object):
                     label = opts.get(r'label', '')
                     msg = self.label(msg, label)
                 dest.write(msg)
-            # stderr may be buffered under win32 when redirected to files,
-            # including stdout.
-            if dest is self._ferr and not getattr(self._ferr, 'closed', False):
-                dest.flush()
         except IOError as err:
-            if (dest is self._ferr
-                and err.errno in (errno.EPIPE, errno.EIO, errno.EBADF)):
-                # no way to report the error, so ignore it
-                return
             raise error.StdioError(err)
         finally:
             self._blockedtimes['stdio_blocked'] += \


More information about the Mercurial-devel mailing list