encoding: add fast-path for ASCII uppercase. stable
authorMartin Geisler <mg@aragost.com>
Mon, 23 Jul 2012 15:55:26 -0600
branchstable
changeset 17236 9fb8312dbdbd
parent 17235 3745ae495ce5
child 17238 57a47190e96c
encoding: add fast-path for ASCII uppercase. This copies the performance hack from encoding.lower (c481761033bd). The case-folding logic that kicks in on case-insensitive filesystems hits encoding.upper hard: with a repository with 75k files, the timings went from hg perfstatus ! wall 3.156000 comb 3.156250 user 1.625000 sys 1.531250 (best of 3) to hg perfstatus ! wall 2.390000 comb 2.390625 user 1.078125 sys 1.312500 (best of 5) This is a 24% decrease. For comparison, Mercurial 2.0 gives: hg perfstatus ! wall 2.172000 comb 2.171875 user 0.984375 sys 1.187500 (best of 5) so we're only 10% slower than before we added the extra case-folding logic. The same decrease is seen when executing 'hg status' as normal, where we go from: hg status --time time: real 4.322 secs (user 2.219+0.000 sys 2.094+0.000) to hg status --time time: real 3.307 secs (user 1.750+0.000 sys 1.547+0.000)
mercurial/encoding.py
--- a/mercurial/encoding.py	Mon Jul 23 15:55:22 2012 -0600
+++ b/mercurial/encoding.py	Mon Jul 23 15:55:26 2012 -0600
@@ -190,6 +190,11 @@
 def upper(s):
     "best-effort encoding-aware case-folding of local string s"
     try:
+        s.decode('ascii') # throw exception for non-ASCII character
+        return s.upper()
+    except UnicodeDecodeError:
+        pass
+    try:
         if isinstance(s, localstr):
             u = s._utf8.decode("utf-8")
         else: