diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-07-30 14:37:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-30 14:37:28 (GMT) |
commit | 9265a877426af4fa5c44cc8482e0198806889350 (patch) | |
tree | 5f49d205eade521ab615059960616e59e53d60ce /Modules/_json.c | |
parent | 8b50e3e2729190d4b65ee9510d81f01bd31f2f7c (diff) | |
download | cpython-9265a877426af4fa5c44cc8482e0198806889350.zip cpython-9265a877426af4fa5c44cc8482e0198806889350.tar.gz cpython-9265a877426af4fa5c44cc8482e0198806889350.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).
(cherry picked from commit 8a758f5b99c5fc3fd32edeac049d7d4a4b7cc163)
Co-authored-by: Marco Paolini <mpaolini@users.noreply.github.com>
Diffstat (limited to 'Modules/_json.c')
-rw-r--r-- | Modules/_json.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Modules/_json.c b/Modules/_json.c index e3aa997..048a965 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; } |