bpo-44987: Speed up unicode normalization of ASCII strings (GH-28283)

This commit is contained in:
Dong-hee Na 2021-09-11 15:04:38 +00:00 committed by GitHub
parent 97ea18eced
commit 9abd07e596
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 0 deletions

View file

@ -287,6 +287,9 @@ Optimizations
* :file:`.pdbrc` is now read with ``'utf-8'`` encoding.
* Pure ASCII strings are now normalized in constant time by :func:`unicodedata.normalize`.
(Contributed by Dong-hee Na in :issue:`bpo-44987`.)
CPython bytecode changes
========================

View file

@ -0,0 +1,2 @@
Pure ASCII strings are now normalized in constant time by :func:`unicodedata.normalize`.
Patch by Dong-hee Na.

View file

@ -807,6 +807,10 @@ is_normalized_quickcheck(PyObject *self, PyObject *input, bool nfc, bool k,
return NO;
}
if (PyUnicode_IS_ASCII(input)) {
return YES;
}
Py_ssize_t i, len;
int kind;
const void *data;