summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2007-03-18 06:45:51 +0000
committerBob Ippolito <bob@redivi.com>2007-03-18 06:45:51 +0000
commit7c19b98b7c2c2b589e12c61316124463510ba3ee (patch)
treedfe497a260c6e5613aab94c655f164078e11cbf6
parenta0fac116e1e5fd038174312c5b52d15a163fcbc8 (diff)
downloadsimplejson-7c19b98b7c2c2b589e12c61316124463510ba3ee.tar.gz
small decoder optimization
git-svn-id: http://simplejson.googlecode.com/svn/trunk@46 a4795897-2c25-0410-b006-0d3caba88fa1
-rw-r--r--simplejson/__init__.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/simplejson/__init__.py b/simplejson/__init__.py
index 8e4f77b..7cccf90 100644
--- a/simplejson/__init__.py
+++ b/simplejson/__init__.py
@@ -212,7 +212,10 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
separators=separators, encoding=encoding,
**kw).encode(obj)
-def load(fp, encoding=None, cls=None, object_hook=None, **kw):
+_default_decoder = JSONDecoder(encoding=None, object_hook=None)
+
+def load(fp, encoding=None, cls=None, object_hook=None,
+ _decode=_default_decoder.decode, **kw):
"""
Deserialize ``fp`` (a ``.read()``-supporting file-like object containing
a JSON document) to a Python object.
@@ -232,13 +235,16 @@ def load(fp, encoding=None, cls=None, object_hook=None, **kw):
To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
kwarg.
"""
+ if cls is None and encoding is None and object_hook is None and not kw:
+ return _decode(fp.read())
if cls is None:
cls = JSONDecoder
if object_hook is not None:
kw['object_hook'] = object_hook
return cls(encoding=encoding, **kw).decode(fp.read())
-def loads(s, encoding=None, cls=None, object_hook=None, **kw):
+def loads(s, encoding=None, cls=None, object_hook=None,
+ _decode=_default_decoder.decode, **kw):
"""
Deserialize ``s`` (a ``str`` or ``unicode`` instance containing a JSON
document) to a Python object.
@@ -256,6 +262,8 @@ def loads(s, encoding=None, cls=None, object_hook=None, **kw):
To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
kwarg.
"""
+ if cls is None and encoding is None and object_hook is None and not kw:
+ return _decode(s)
if cls is None:
cls = JSONDecoder
if object_hook is not None: