Patchwork [3,of,3] dirstate._normalize: don't construct dirfoldmap if not necessary

login
register
mail settings
Submitter Siddharth Agarwal
Date April 1, 2015, 3:24 a.m.
Message ID <9a023f039ed86ed46941.1427858683@devbig136.prn2.facebook.com>
Download mbox | patch
Permalink /patch/8406/
State Accepted
Headers show

Comments

Siddharth Agarwal - April 1, 2015, 3:24 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1427855677 25200
#      Tue Mar 31 19:34:37 2015 -0700
# Node ID 9a023f039ed86ed4694174223b5f6c3965e99723
# Parent  08b7cf83a76bfa709fd94381b1fb1708ca42465f
dirstate._normalize: don't construct dirfoldmap if not necessary

Constructing the dirfoldmap is expensive, so if there's a hit in the
filefoldmap, don't construct the directory foldmap.

This helps with cases like 'hg add foo' where foo is already tracked: for a
large repository, the operation goes from 1.5 seconds to 1.2 (which is still
way too much, but that's a matter for another day.)
Matt Mackall - April 1, 2015, 4:10 p.m.
On Tue, 2015-03-31 at 20:24 -0700, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0@fb.com>
> # Date 1427855677 25200
> #      Tue Mar 31 19:34:37 2015 -0700
> # Node ID 9a023f039ed86ed4694174223b5f6c3965e99723
> # Parent  08b7cf83a76bfa709fd94381b1fb1708ca42465f
> dirstate._normalize: don't construct dirfoldmap if not necessary

These are queued for default, thanks.

Patch

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -509,8 +509,9 @@ 
 
     def _normalize(self, path, isknown, ignoremissing=False, exists=None):
         normed = util.normcase(path)
-        folded = self._filefoldmap.get(normed,
-                                       self._dirfoldmap.get(normed, None))
+        folded = self._filefoldmap.get(normed, None)
+        if folded is None:
+            folded = self._dirfoldmap.get(normed, None)
         if folded is None:
             if isknown:
                 folded = path