Skip to content

Commit 284d568

Browse files
committed
Split out the decode whitespace change to a separate PR
Keep only the encoder floatstr deferral here; the decoder whitespace skip is contentious (depends on gh-117397 and shows mixed results on large documents) and moves to its own PR.
1 parent 167626b commit 284d568

2 files changed

Lines changed: 6 additions & 12 deletions

File tree

Lib/json/decoder.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -355,16 +355,10 @@ def decode(self, s, _w=WHITESPACE.match):
355355
containing a JSON document).
356356
357357
"""
358-
# Skip the WHITESPACE.match() call (and its match-object allocation)
359-
# for the common case where there is no leading whitespace.
360-
idx = _w(s, 0).end() if s and s[0] in ' \t\n\r' else 0
361-
obj, end = self.raw_decode(s, idx=idx)
362-
# Likewise avoid the trailing-whitespace match when the parse already
363-
# consumed the whole string.
358+
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
359+
end = _w(s, end).end()
364360
if end != len(s):
365-
end = _w(s, end).end()
366-
if end != len(s):
367-
raise JSONDecodeError("Extra data", s, end)
361+
raise JSONDecodeError("Extra data", s, end)
368362
return obj
369363

370364
def raw_decode(self, s, idx=0):
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Speed up :func:`json.loads` and :func:`json.dumps` for small documents by
2-
avoiding a redundant whitespace scan on decode and by building the float
3-
helper only on the Python encoding path. Patch by Bernát Gábor.
1+
Speed up :func:`json.dumps` for small documents by building the float
2+
formatting helper only on the slower Python encoding path instead of on every
3+
call. Patch by Bernát Gábor.

0 commit comments

Comments
 (0)