summaryrefslogtreecommitdiffstats
path: root/Lib/json/scanner.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-09-04 20:16:53 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-09-04 20:16:53 (GMT)
commit7d6e076f6d8dd48cfd748b02dad17dbeb0b346a3 (patch)
tree3d355bd888b6e2aaba52f33807d183055d61b700 /Lib/json/scanner.py
parentd9107aadeda663173eb68c412396e5e3353a4059 (diff)
downloadcpython-7d6e076f6d8dd48cfd748b02dad17dbeb0b346a3.zip
cpython-7d6e076f6d8dd48cfd748b02dad17dbeb0b346a3.tar.gz
cpython-7d6e076f6d8dd48cfd748b02dad17dbeb0b346a3.tar.bz2
Issue #7451: Improve decoding performance of JSON objects, and reduce
the memory consumption of said decoded objects when they use the same strings as keys.
Diffstat (limited to 'Lib/json/scanner.py')
-rw-r--r--Lib/json/scanner.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/json/scanner.py b/Lib/json/scanner.py
index b4f3561..23eef61 100644
--- a/Lib/json/scanner.py
+++ b/Lib/json/scanner.py
@@ -22,6 +22,8 @@ def py_make_scanner(context):
parse_int = context.parse_int
parse_constant = context.parse_constant
object_hook = context.object_hook
+ object_pairs_hook = context.object_pairs_hook
+ memo = context.memo
def _scan_once(string, idx):
try:
@@ -33,7 +35,7 @@ def py_make_scanner(context):
return parse_string(string, idx + 1, strict)
elif nextchar == '{':
return parse_object((string, idx + 1), strict,
- _scan_once, object_hook, object_pairs_hook)
+ _scan_once, object_hook, object_pairs_hook, memo)
elif nextchar == '[':
return parse_array((string, idx + 1), _scan_once)
elif nextchar == 'n' and string[idx:idx + 4] == 'null':
@@ -60,6 +62,12 @@ def py_make_scanner(context):
else:
raise StopIteration
+ def scan_once(string, idx):
+ try:
+ return _scan_once(string, idx)
+ finally:
+ memo.clear()
+
return _scan_once
make_scanner = c_make_scanner or py_make_scanner