changeset 33981:5cb0a8fe096e

dirstate: perform transactions with _copymap using single call, where possible This replaces patterns such as this: ``` if f in self._copymap: del self._copymap[f] ``` with this: ``` self._copymap.pop(f, None) ``` Although eliminating the extra lookup/call may be a negligible performance win in the standard dirstate, alternative implementations, such as [sqldirstate](https://bitbucket.org/facebook/hg-experimental/src/default/sqldirstate/) may see a bigger win where each of these calls results in an RPC, so the savings is greater. Test Plan: `make tests` Differential Revision: https://phab.mercurial-scm.org/D493
author Michael Bolin <mbolin@fb.com>
date Wed, 23 Aug 2017 18:24:57 +0000
parents 8abbae93045a
children 6d9e7145d8d9
files mercurial/dirstate.py
diffstat 1 files changed, 14 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dirstate.py	Thu Aug 24 20:25:16 2017 -0700
+++ b/mercurial/dirstate.py	Wed Aug 23 18:24:57 2017 +0000
@@ -406,13 +406,15 @@
 
                 # Discard 'm' markers when moving away from a merge state
                 if s[0] == 'm':
-                    if f in self._copymap:
-                        copies[f] = self._copymap[f]
+                    source = self._copymap.get(f)
+                    if source:
+                        copies[f] = source
                     self.normallookup(f)
                 # Also fix up otherparent markers
                 elif s[0] == 'n' and s[2] == -2:
-                    if f in self._copymap:
-                        copies[f] = self._copymap[f]
+                    source = self._copymap.get(f)
+                    if source:
+                        copies[f] = source
                     self.add(f)
         return copies
 
@@ -518,8 +520,7 @@
             self._copymap[dest] = source
             self._updatedfiles.add(source)
             self._updatedfiles.add(dest)
-        elif dest in self._copymap:
-            del self._copymap[dest]
+        elif self._copymap.pop(dest, None):
             self._updatedfiles.add(dest)
 
     def copied(self, file):
@@ -568,8 +569,7 @@
         mtime = s.st_mtime
         self._addpath(f, 'n', s.st_mode,
                       s.st_size & _rangemask, mtime & _rangemask)
-        if f in self._copymap:
-            del self._copymap[f]
+        self._copymap.pop(f, None)
         if f in self._nonnormalset:
             self._nonnormalset.remove(f)
         if mtime > self._lastnormaltime:
@@ -597,8 +597,7 @@
             if entry[0] == 'm' or entry[0] == 'n' and entry[2] == -2:
                 return
         self._addpath(f, 'n', 0, -1, -1)
-        if f in self._copymap:
-            del self._copymap[f]
+        self._copymap.pop(f, None)
         if f in self._nonnormalset:
             self._nonnormalset.remove(f)
 
@@ -613,15 +612,12 @@
         else:
             # add-like
             self._addpath(f, 'n', 0, -2, -1)
-
-        if f in self._copymap:
-            del self._copymap[f]
+        self._copymap.pop(f, None)
 
     def add(self, f):
         '''Mark a file added.'''
         self._addpath(f, 'a', 0, -1, -1)
-        if f in self._copymap:
-            del self._copymap[f]
+        self._copymap.pop(f, None)
 
     def remove(self, f):
         '''Mark a file removed.'''
@@ -638,8 +634,8 @@
                 self._otherparentset.add(f)
         self._map[f] = dirstatetuple('r', 0, size, 0)
         self._nonnormalset.add(f)
-        if size == 0 and f in self._copymap:
-            del self._copymap[f]
+        if size == 0:
+            self._copymap.pop(f, None)
 
     def merge(self, f):
         '''Mark a file merged.'''
@@ -655,8 +651,7 @@
             del self._map[f]
             if f in self._nonnormalset:
                 self._nonnormalset.remove(f)
-            if f in self._copymap:
-                del self._copymap[f]
+            self._copymap.pop(f, None)
 
     def _discoverpath(self, path, normed, ignoremissing, exists, storemap):
         if exists is None: