summaryrefslogtreecommitdiffstats
path: root/Modules/_json.c
diff options
context:
space:
mode:
authorMarco Paolini <mpaolini@users.noreply.github.com>2019-07-30 14:16:34 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2019-07-30 14:16:34 (GMT)
commit8a758f5b99c5fc3fd32edeac049d7d4a4b7cc163 (patch)
treed56c7f01cdf44565a93f5a3373fb2992fccaf5ee /Modules/_json.c
parent9211e2fd81fe1db6f73ded70752b144cc9691ab6 (diff)
downloadcpython-8a758f5b99c5fc3fd32edeac049d7d4a4b7cc163.zip
cpython-8a758f5b99c5fc3fd32edeac049d7d4a4b7cc163.tar.gz
cpython-8a758f5b99c5fc3fd32edeac049d7d4a4b7cc163.tar.bz2
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).
Diffstat (limited to 'Modules/_json.c')
-rw-r--r--Modules/_json.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/Modules/_json.c b/Modules/_json.c
index 38beb6f..76da1d3 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -439,7 +439,7 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next
if (c == '"' || c == '\\') {
break;
}
- else if (strict && c <= 0x1f) {
+ else if (c <= 0x1f && strict) {
raise_errmsg("Invalid control character at", pystr, next);
goto bail;
}