[PATCH 3 of 6 v2] dirstate: make dirstate._join a bit faster on posix

Kostia Balytskyi ikostia at fb.com
Tue Sep 19 12:57:47 EDT 2017


# HG changeset patch
# User Kostia Balytskyi <ikostia at fb.com>
# Date 1505837513 25200
#      Tue Sep 19 09:11:53 2017 -0700
# Node ID 3294e39ad1c3adf26308eae859280437f1671220
# Parent  db7c6d368422041bb0d5ff5dafcd4cdaf3943fac
dirstate: make dirstate._join a bit faster on posix

This is a micro-optimization, suggested by @quark for one of the previous
patches. It is safe to land the series without this micro-optimization.

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -268,8 +268,17 @@ class dirstate(object):
     def _checkcase(self):
         return not util.fscasesensitive(self._join('.hg'))
 
-    def _join(self, f):
-        return util.absjoin(self._rootdir, f)
+    if pycompat.osname == 'nt':
+        def _join(self, f):
+            return util.absjoin(self._rootdir, f)
+
+    else:
+        def _join(self, f):
+            # The cross-platform _join() has windows-specific logic that
+            # is much more branchy. Since this is called
+            # O(files in working copy) times regularly, we microoptimize here.
+            # This is safe because f is always a relative path.
+            return self._rootdir + f
 
     def flagfunc(self, buildfallback):
         if self._checklink and self._checkexec:


More information about the Mercurial-devel mailing list