# HG changeset patch # User Michael Bolin # Date 1503512697 0 # Node ID 5cb0a8fe096e4171c0456ed499bef2301623a6f9 # Parent 8abbae93045a222becd3f87c6e828a41729f2953 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 diff -r 8abbae93045a -r 5cb0a8fe096e mercurial/dirstate.py --- 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: