Mercurial > public > mercurial-scm > hg
comparison mercurial/pure/charencode.py @ 33926:f4433f2713d0
encoding: add function to test if a str consists of ASCII characters
Most strings are ASCII. Let's optimize for it.
Using uint64_t is slightly faster than uint32_t on 64bit system, but there
isn't huge difference.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 23 Apr 2017 12:59:42 +0900 |
parents | b9101467d88b |
children | 5307cc57f271 |
comparison
equal
deleted
inserted
replaced
33925:2c37f9dabc32 | 33926:f4433f2713d0 |
---|---|
10 import array | 10 import array |
11 | 11 |
12 from .. import ( | 12 from .. import ( |
13 pycompat, | 13 pycompat, |
14 ) | 14 ) |
15 | |
16 def isasciistr(s): | |
17 try: | |
18 s.decode('ascii') | |
19 return True | |
20 except UnicodeDecodeError: | |
21 return False | |
15 | 22 |
16 def asciilower(s): | 23 def asciilower(s): |
17 '''convert a string to lowercase if ASCII | 24 '''convert a string to lowercase if ASCII |
18 | 25 |
19 Raises UnicodeDecodeError if non-ASCII characters are found.''' | 26 Raises UnicodeDecodeError if non-ASCII characters are found.''' |