log: cache diffopts instance
authorYuya Nishihara <yuya@tcha.org>
Sun, 29 Apr 2018 15:44:17 +0900
changeset 37837 e0f30c91dfd8
parent 37836 86e7a57449fa
child 37838 3fe1c9263024
log: cache diffopts instance It appears that calling patch.diff*opts() repeatedly has some cost. $ hg log -T '{rev}\n' -R mercurial --time > /dev/null (orig) time: real 4.430 secs (user 4.370+0.000 sys 0.050+0.000) (new) time: real 1.950 secs (user 1.880+0.000 sys 0.060+0.000) 'diffopts or {}' isn't necessary as patch.diff*opts() accepts opts=None.
mercurial/logcmdutil.py
--- a/mercurial/logcmdutil.py	Sat May 05 18:06:45 2018 -0700
+++ b/mercurial/logcmdutil.py	Sun Apr 29 15:44:17 2018 +0900
@@ -154,6 +154,7 @@
         self.repo = repo
         self.buffered = buffered
         self._differ = differ or changesetdiffer()
+        self._diffopts = patch.diffallopts(ui, diffopts)
         self.diffopts = diffopts or {}
         self.header = {}
         self.hunk = {}
@@ -300,13 +301,12 @@
     def _showpatch(self, ctx):
         stat = self.diffopts.get('stat')
         diff = self.diffopts.get('patch')
-        diffopts = patch.diffallopts(self.ui, self.diffopts)
         if stat:
-            self._differ.showdiff(self.ui, ctx, diffopts, stat=True)
+            self._differ.showdiff(self.ui, ctx, self._diffopts, stat=True)
         if stat and diff:
             self.ui.write("\n")
         if diff:
-            self._differ.showdiff(self.ui, ctx, diffopts, stat=False)
+            self._differ.showdiff(self.ui, ctx, self._diffopts, stat=False)
         if stat or diff:
             self.ui.write("\n")
 
@@ -316,6 +316,7 @@
     def __init__(self, ui, repo, fm, differ=None, diffopts=None,
                  buffered=False):
         changesetprinter.__init__(self, ui, repo, differ, diffopts, buffered)
+        self._diffopts = patch.difffeatureopts(ui, diffopts, git=True)
         self._fm = fm
 
     def close(self):
@@ -369,14 +370,13 @@
 
         stat = self.diffopts.get('stat')
         diff = self.diffopts.get('patch')
-        diffopts = patch.difffeatureopts(self.ui, self.diffopts, git=True)
         if stat:
             self.ui.pushbuffer()
-            self._differ.showdiff(self.ui, ctx, diffopts, stat=True)
+            self._differ.showdiff(self.ui, ctx, self._diffopts, stat=True)
             fm.data(diffstat=self.ui.popbuffer())
         if diff:
             self.ui.pushbuffer()
-            self._differ.showdiff(self.ui, ctx, diffopts, stat=False)
+            self._differ.showdiff(self.ui, ctx, self._diffopts, stat=False)
             fm.data(diff=self.ui.popbuffer())
 
 class changesettemplater(changesetprinter):