mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
gh-95382: Improve performance of json encoder with indent (GH-118105)
This commit is contained in:
parent
7758be4318
commit
05adfbba2a
3 changed files with 105 additions and 47 deletions
|
|
@ -244,15 +244,18 @@ class JSONEncoder(object):
|
|||
return text
|
||||
|
||||
|
||||
if (_one_shot and c_make_encoder is not None
|
||||
and self.indent is None):
|
||||
if self.indent is None or isinstance(self.indent, str):
|
||||
indent = self.indent
|
||||
else:
|
||||
indent = ' ' * self.indent
|
||||
if _one_shot and c_make_encoder is not None:
|
||||
_iterencode = c_make_encoder(
|
||||
markers, self.default, _encoder, self.indent,
|
||||
markers, self.default, _encoder, indent,
|
||||
self.key_separator, self.item_separator, self.sort_keys,
|
||||
self.skipkeys, self.allow_nan)
|
||||
else:
|
||||
_iterencode = _make_iterencode(
|
||||
markers, self.default, _encoder, self.indent, floatstr,
|
||||
markers, self.default, _encoder, indent, floatstr,
|
||||
self.key_separator, self.item_separator, self.sort_keys,
|
||||
self.skipkeys, _one_shot)
|
||||
return _iterencode(o, 0)
|
||||
|
|
@ -272,9 +275,6 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
|
|||
_intstr=int.__repr__,
|
||||
):
|
||||
|
||||
if _indent is not None and not isinstance(_indent, str):
|
||||
_indent = ' ' * _indent
|
||||
|
||||
def _iterencode_list(lst, _current_indent_level):
|
||||
if not lst:
|
||||
yield '[]'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue