# HG changeset patch # User Bob Ippolito <bob@redivi.com> # Date 1174200351 0 # Sun Mar 18 06:45:51 2007 +0000 # Node ID 0b63b759242cc6a4bb9fb165ad22ba48a37395ad # Parent 3dd63130ded9450b0d3de71e4cc68103e47cd61b small decoder optimization git-svn-id: http://simplejson.googlecode.com/svn/trunk@46 a4795897-2c25-0410-b006-0d3caba88fa1 diff --git a/simplejson/__init__.py b/simplejson/__init__.py --- a/simplejson/__init__.py +++ b/simplejson/__init__.py @@ -212,7 +212,10 @@ 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 @@ 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 @@ 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: