comparison mercurial/encoding.py @ 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 885bd7c5c7e3
children f473a1fe5c7c
comparison
equal deleted inserted replaced
24577:bf55df007535 24578:ac08de78de7f
294 impl = getattr(parsers, 'asciilower', _asciilower) 294 impl = getattr(parsers, 'asciilower', _asciilower)
295 global asciilower 295 global asciilower
296 asciilower = impl 296 asciilower = impl
297 return impl(s) 297 return impl(s)
298 298
299 def _asciiupper(s):
300 '''convert a string to uppercase if ASCII
301
302 Raises UnicodeDecodeError if non-ASCII characters are found.'''
303 s.decode('ascii')
304 return s.upper()
305
306 def asciiupper(s):
307 # delay importing avoids cyclic dependency around "parsers" in
308 # pure Python build (util => i18n => encoding => parsers => util)
309 import parsers
310 impl = getattr(parsers, 'asciiupper', _asciiupper)
311 global asciiupper
312 asciiupper = impl
313 return impl(s)
314
299 def lower(s): 315 def lower(s):
300 "best-effort encoding-aware case-folding of local string s" 316 "best-effort encoding-aware case-folding of local string s"
301 try: 317 try:
302 return asciilower(s) 318 return asciilower(s)
303 except UnicodeDecodeError: 319 except UnicodeDecodeError:
318 raise error.Abort(k, hint="please check your locale settings") 334 raise error.Abort(k, hint="please check your locale settings")
319 335
320 def upper(s): 336 def upper(s):
321 "best-effort encoding-aware case-folding of local string s" 337 "best-effort encoding-aware case-folding of local string s"
322 try: 338 try:
323 s.decode('ascii') # throw exception for non-ASCII character 339 return asciiupper(s)
324 return s.upper()
325 except UnicodeDecodeError: 340 except UnicodeDecodeError:
326 pass 341 pass
327 try: 342 try:
328 if isinstance(s, localstr): 343 if isinstance(s, localstr):
329 u = s._utf8.decode("utf-8") 344 u = s._utf8.decode("utf-8")