From patchwork Sun May 6 02:41:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1,of,2] log: cache diffopts instance From: Yuya Nishihara X-Patchwork-Id: 31270 Message-Id: <5ab73949f3870cfaa4b1.1525574484@mimosa> To: mercurial-devel@mercurial-scm.org Date: Sun, 06 May 2018 11:41:24 +0900 # HG changeset patch # User Yuya Nishihara # Date 1524984257 -32400 # Sun Apr 29 15:44:17 2018 +0900 # Node ID 5ab73949f3870cfaa4b16180511f22a8f51130a8 # Parent 86e7a57449fa4f854d730cafd505ab089c25df76 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. diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py --- a/mercurial/logcmdutil.py +++ b/mercurial/logcmdutil.py @@ -154,6 +154,7 @@ class changesetprinter(object): 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 @@ class changesetprinter(object): 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 @@ class changesetformatter(changesetprinte 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 @@ class changesetformatter(changesetprinte 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):