##// END OF EJS Templates
encoding: add fast path of from/toutf8b() for ASCII strings...
Yuya Nishihara -
r33929:6c119dbf default
parent child Browse files
Show More
@@ -494,6 +494,8 b' def toutf8b(s):'
494 internal surrogate encoding as a UTF-8 string.)
494 internal surrogate encoding as a UTF-8 string.)
495 '''
495 '''
496
496
497 if not isinstance(s, localstr) and isasciistr(s):
498 return s
497 if "\xed" not in s:
499 if "\xed" not in s:
498 if isinstance(s, localstr):
500 if isinstance(s, localstr):
499 return s._utf8
501 return s._utf8
@@ -544,6 +546,8 b' def fromutf8b(s):'
544 True
546 True
545 '''
547 '''
546
548
549 if isasciistr(s):
550 return s
547 # fast path - look for uDxxx prefixes in s
551 # fast path - look for uDxxx prefixes in s
548 if "\xed" not in s:
552 if "\xed" not in s:
549 return s
553 return s
@@ -34,6 +34,12 b' class LocalEncodingTest(unittest.TestCas'
34 self.assertTrue(s is encoding.tolocal(s))
34 self.assertTrue(s is encoding.tolocal(s))
35 self.assertTrue(s is encoding.fromlocal(s))
35 self.assertTrue(s is encoding.fromlocal(s))
36
36
37 class Utf8bEncodingTest(unittest.TestCase):
38 def testasciifastpath(self):
39 s = b'\0' * 100
40 self.assertTrue(s is encoding.toutf8b(s))
41 self.assertTrue(s is encoding.fromutf8b(s))
42
37 if __name__ == '__main__':
43 if __name__ == '__main__':
38 import silenttestrunner
44 import silenttestrunner
39 silenttestrunner.main(__name__)
45 silenttestrunner.main(__name__)
General Comments 0
You need to be logged in to leave comments. Login now