mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #23206: Make `json.dumps(..., ensure_ascii=False)
as fast as the default case of
ensure_ascii=True
`. Patch by Naoki Inada.
This commit is contained in:
parent
2cae11e87e
commit
dc3eaa80d4
5 changed files with 142 additions and 7 deletions
|
@ -6,6 +6,10 @@ try:
|
|||
from _json import encode_basestring_ascii as c_encode_basestring_ascii
|
||||
except ImportError:
|
||||
c_encode_basestring_ascii = None
|
||||
try:
|
||||
from _json import encode_basestring as c_encode_basestring
|
||||
except ImportError:
|
||||
c_encode_basestring = None
|
||||
try:
|
||||
from _json import make_encoder as c_make_encoder
|
||||
except ImportError:
|
||||
|
@ -30,7 +34,7 @@ for i in range(0x20):
|
|||
INFINITY = float('inf')
|
||||
FLOAT_REPR = repr
|
||||
|
||||
def encode_basestring(s):
|
||||
def py_encode_basestring(s):
|
||||
"""Return a JSON representation of a Python string
|
||||
|
||||
"""
|
||||
|
@ -39,6 +43,9 @@ def encode_basestring(s):
|
|||
return '"' + ESCAPE.sub(replace, s) + '"'
|
||||
|
||||
|
||||
encode_basestring = (c_encode_basestring or py_encode_basestring)
|
||||
|
||||
|
||||
def py_encode_basestring_ascii(s):
|
||||
"""Return an ASCII-only JSON representation of a Python string
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue