Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9abd07e

Browse files
authored
bpo-44987: Speed up unicode normalization of ASCII strings (GH-28283)
1 parent 97ea18e commit 9abd07e

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

Doc/whatsnew/3.11.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ Optimizations
287287

288288
* :file:`.pdbrc` is now read with ``'utf-8'`` encoding.
289289

290+
* Pure ASCII strings are now normalized in constant time by :func:`unicodedata.normalize`.
291+
(Contributed by Dong-hee Na in :issue:`bpo-44987`.)
292+
290293

291294
CPython bytecode changes
292295
========================
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Pure ASCII strings are now normalized in constant time by :func:`unicodedata.normalize`.
2+
Patch by Dong-hee Na.

Modules/unicodedata.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,10 @@ is_normalized_quickcheck(PyObject *self, PyObject *input, bool nfc, bool k,
807807
return NO;
808808
}
809809

810+
if (PyUnicode_IS_ASCII(input)) {
811+
return YES;
812+
}
813+
810814
Py_ssize_t i, len;
811815
int kind;
812816
const void *data;

0 commit comments

Comments
 (0)