From 7d6e076f6d8dd48cfd748b02dad17dbeb0b346a3 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sat, 4 Sep 2010 20:16:53 +0000 Subject: 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. --- Lib/json/scanner.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'Lib/json/scanner.py') diff --git a/Lib/json/scanner.py b/Lib/json/scanner.py index b4f356146fe..23eef61b94b 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 -- cgit v1.2.3