Patchwork [1,of,3,V2] revlog: avoid calculating "flags" twice in revision()

login
register
mail settings
Submitter Jun Wu
Date April 3, 2017, 1:42 a.m.
Message ID <0413ffdb4a294c9d4c7b.1491183779@x1c>
Download mbox | patch
Permalink /patch/19923/
State Accepted
Headers show

Comments

Jun Wu - April 3, 2017, 1:42 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1491182712 25200
#      Sun Apr 02 18:25:12 2017 -0700
# Node ID 0413ffdb4a294c9d4c7b9b9c41eb733f82d7556b
# Parent  04ec317b81280c189fcea33a05c8cbbac3c186b1
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 0413ffdb4a29
revlog: avoid calculating "flags" twice in revision()

This is more consistent with other code in "revision()" - prefer performance
to code length.

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1268,4 +1268,5 @@  class revlog(object):
 
         cachedrev = None
+        flags = None
         if node == nullid:
             return ""
@@ -1278,6 +1279,8 @@  class revlog(object):
                 if rev is None:
                     rev = self.rev(node)
+                if flags is None:
+                    flags = self.flags(rev)
                 # no extra flags set, no flag processor runs, text = rawtext
-                if self.flags(rev) == REVIDX_DEFAULT_FLAGS:
+                if flags == REVIDX_DEFAULT_FLAGS:
                     return self._cache[2]
 
@@ -1303,6 +1306,8 @@  class revlog(object):
         rawtext = mdiff.patches(rawtext, bins)
 
-        text, validatehash = self._processflags(rawtext, self.flags(rev),
-                                                'read', raw=raw)
+        if flags is None:
+            flags = self.flags(rev)
+
+        text, validatehash = self._processflags(rawtext, flags, 'read', raw=raw)
         if validatehash:
             self.checkhash(text, node, rev=rev)