changeset 24578:ac08de78de7f

encoding: use parsers.asciiupper when available This is used on Windows and Cygwin, and the gains from this are expected to be similar to what was seen in 80f2b63dd83a.
author Siddharth Agarwal <sid0@fb.com>
date Tue, 31 Mar 2015 15:22:09 -0700
parents bf55df007535
children 37a2b446985f
files mercurial/encoding.py
diffstat 1 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/encoding.py	Tue Mar 31 13:46:21 2015 -0700
+++ b/mercurial/encoding.py	Tue Mar 31 15:22:09 2015 -0700
@@ -296,6 +296,22 @@
     asciilower = impl
     return impl(s)
 
+def _asciiupper(s):
+    '''convert a string to uppercase if ASCII
+
+    Raises UnicodeDecodeError if non-ASCII characters are found.'''
+    s.decode('ascii')
+    return s.upper()
+
+def asciiupper(s):
+    # delay importing avoids cyclic dependency around "parsers" in
+    # pure Python build (util => i18n => encoding => parsers => util)
+    import parsers
+    impl = getattr(parsers, 'asciiupper', _asciiupper)
+    global asciiupper
+    asciiupper = impl
+    return impl(s)
+
 def lower(s):
     "best-effort encoding-aware case-folding of local string s"
     try:
@@ -320,8 +336,7 @@
 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()
+        return asciiupper(s)
     except UnicodeDecodeError:
         pass
     try: