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

Skip to content

Commit 8a758f5

Browse files
mpaolinincoghlan
authored andcommitted
bpo-37587: Make json.loads faster for long strings (GH-14752)
When scanning the string, most characters are valid, so checking for invalid characters first means never needing to check the value of strict on valid strings, and only needing to check it on invalid characters when doing non-strict parsing of invalid strings. This provides a measurable reduction in per-character processing time (~11% in the pre-merge patch testing).
1 parent 9211e2f commit 8a758f5

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make json.loads faster for long strings. (Patch by Marco Paolini)

Modules/_json.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next
439439
if (c == '"' || c == '\\') {
440440
break;
441441
}
442-
else if (strict && c <= 0x1f) {
442+
else if (c <= 0x1f && strict) {
443443
raise_errmsg("Invalid control character at", pystr, next);
444444
goto bail;
445445
}

0 commit comments

Comments
 (0)