comparison mercurial/ui.py @ 41306:e8273eaa0726 stable

ui: inline _writenobuf() into write() due to performance issue I'll remove redundant conditions later in this series.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 24 Jan 2019 21:35:55 +0900
parents b4a3abdc790d
children 26ee61c33dee
comparison
equal deleted inserted replaced
41305:b4a3abdc790d 41306:e8273eaa0726
1006 label = opts.get(r'label', '') 1006 label = opts.get(r'label', '')
1007 if label and self._bufferapplylabels: 1007 if label and self._bufferapplylabels:
1008 self._buffers[-1].extend(self.label(a, label) for a in args) 1008 self._buffers[-1].extend(self.label(a, label) for a in args)
1009 else: 1009 else:
1010 self._buffers[-1].extend(args) 1010 self._buffers[-1].extend(args)
1011 else: 1011 return
1012 self._writenobuf(dest, *args, **opts) 1012
1013 1013 # inliend _writenobuf() for speed
1014 def write_err(self, *args, **opts):
1015 self._write(self._ferr, *args, **opts)
1016
1017 def _write(self, dest, *args, **opts):
1018 # update write() as well if you touch this code
1019 if self._isbuffered(dest):
1020 label = opts.get(r'label', '')
1021 if label and self._bufferapplylabels:
1022 self._buffers[-1].extend(self.label(a, label) for a in args)
1023 else:
1024 self._buffers[-1].extend(args)
1025 else:
1026 self._writenobuf(dest, *args, **opts)
1027
1028 def _writenobuf(self, dest, *args, **opts):
1029 self._progclear() 1014 self._progclear()
1030 msg = b''.join(args) 1015 msg = b''.join(args)
1031 1016
1032 # opencode timeblockedsection because this is a critical path 1017 # opencode timeblockedsection because this is a critical path
1033 starttime = util.timer() 1018 starttime = util.timer()
1059 raise error.StdioError(err) 1044 raise error.StdioError(err)
1060 finally: 1045 finally:
1061 self._blockedtimes['stdio_blocked'] += \ 1046 self._blockedtimes['stdio_blocked'] += \
1062 (util.timer() - starttime) * 1000 1047 (util.timer() - starttime) * 1000
1063 1048
1049 def write_err(self, *args, **opts):
1050 self._write(self._ferr, *args, **opts)
1051
1052 def _write(self, dest, *args, **opts):
1053 # update write() as well if you touch this code
1054 if self._isbuffered(dest):
1055 label = opts.get(r'label', '')
1056 if label and self._bufferapplylabels:
1057 self._buffers[-1].extend(self.label(a, label) for a in args)
1058 else:
1059 self._buffers[-1].extend(args)
1060 else:
1061 self._writenobuf(dest, *args, **opts)
1062
1063 def _writenobuf(self, dest, *args, **opts):
1064 # update write() as well if you touch this code
1065 self._progclear()
1066 msg = b''.join(args)
1067
1068 # opencode timeblockedsection because this is a critical path
1069 starttime = util.timer()
1070 try:
1071 if dest is self._ferr and not getattr(self._fout, 'closed', False):
1072 self._fout.flush()
1073 if getattr(dest, 'structured', False):
1074 # channel for machine-readable output with metadata, where
1075 # no extra colorization is necessary.
1076 dest.write(msg, **opts)
1077 elif self._colormode == 'win32':
1078 # windows color printing is its own can of crab, defer to
1079 # the color module and that is it.
1080 color.win32print(self, dest.write, msg, **opts)
1081 else:
1082 if self._colormode is not None:
1083 label = opts.get(r'label', '')
1084 msg = self.label(msg, label)
1085 dest.write(msg)
1086 # stderr may be buffered under win32 when redirected to files,
1087 # including stdout.
1088 if dest is self._ferr and not getattr(self._ferr, 'closed', False):
1089 dest.flush()
1090 except IOError as err:
1091 if (dest is self._ferr
1092 and err.errno in (errno.EPIPE, errno.EIO, errno.EBADF)):
1093 # no way to report the error, so ignore it
1094 return
1095 raise error.StdioError(err)
1096 finally:
1097 self._blockedtimes['stdio_blocked'] += \
1098 (util.timer() - starttime) * 1000
1099
1064 def _writemsg(self, dest, *args, **opts): 1100 def _writemsg(self, dest, *args, **opts):
1065 _writemsgwith(self._write, dest, *args, **opts) 1101 _writemsgwith(self._write, dest, *args, **opts)
1066 1102
1067 def _writemsgnobuf(self, dest, *args, **opts): 1103 def _writemsgnobuf(self, dest, *args, **opts):
1068 _writemsgwith(self._writenobuf, dest, *args, **opts) 1104 _writemsgwith(self._writenobuf, dest, *args, **opts)