Skip to content

Commit 42f95ed

Browse files
committed
Make ASCII-lowercasing quicker when it's a no-op
1 parent 333e9b9 commit 42f95ed

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

html5lib/utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from __future__ import absolute_import, division, unicode_literals
22

3+
import re
34
import sys
5+
46
from types import ModuleType
57

68
from six import text_type
@@ -128,5 +130,11 @@ def wrapped(*args, **kwargs):
128130
return wrapped
129131

130132

133+
_upper = re.compile(u"[A-Z]")
134+
135+
131136
def ascii_lowercase(s):
132-
return s.translate(asciiUpper2Lower)
137+
if _upper.search(s) is not None:
138+
return s.translate(asciiUpper2Lower)
139+
else:
140+
return s

0 commit comments

Comments
 (0)