Commit 8a758f5b authored by Marco Paolini's avatar Marco Paolini Committed by Nick Coghlan

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).
parent 9211e2fd
Make json.loads faster for long strings. (Patch by Marco Paolini)
......@@ -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;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment