bpo-32677: Optimize str.isascii() (GH-5356)

This commit is contained in:
INADA Naoki 2018-01-28 09:59:12 +09:00 committed by GitHub
parent ea8fc52e75
commit bea57060c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 4 deletions

View file

@ -916,6 +916,13 @@ class BaseTest:
self.checkequal(True, '\x00\x7f', 'isascii')
self.checkequal(False, '\x80', 'isascii')
self.checkequal(False, '\xe9', 'isascii')
# bytes.isascii() and bytearray.isascii() has optimization which
# check 4 or 8 bytes at once. So check some alignments.
for p in range(8):
self.checkequal(True, ' '*p + '\x7f', 'isascii')
self.checkequal(False, ' '*p + '\x80', 'isascii')
self.checkequal(True, ' '*p + '\x7f' + ' '*8, 'isascii')
self.checkequal(False, ' '*p + '\x80' + ' '*8, 'isascii')
def test_isdigit(self):
self.checkequal(False, '', 'isdigit')