diff options
author | Alexander Dutton <alexander.dutton@it.ox.ac.uk> | 2015-02-15 20:06:05 +0000 |
---|---|---|
committer | Alexander Dutton <alexander.dutton@it.ox.ac.uk> | 2015-02-15 20:06:05 +0000 |
commit | c4372cdb3829138a1e5287e1c4ef8dc9c6c5b5a5 (patch) | |
tree | ae567d71eb5a71d1f7307b0914e6b11ff4ffff0e /jsonpointer.py | |
parent | 76b542b3fbfb3ef2a1f9fd289e8a74765c5cb53f (diff) | |
download | python-json-pointer-c4372cdb3829138a1e5287e1c4ef8dc9c6c5b5a5.tar.gz |
Optimize in get_part for the common cases of doc being dict or list
Diffstat (limited to 'jsonpointer.py')
-rw-r--r-- | jsonpointer.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/jsonpointer.py b/jsonpointer.py index 29a71f5..3e8b31c 100644 --- a/jsonpointer.py +++ b/jsonpointer.py @@ -196,7 +196,12 @@ class JsonPointer(object): def get_part(self, doc, part): """ Returns the next step in the correct type """ - if isinstance(doc, Sequence): + # Optimize for common cases of doc being a dict or list, but not a + # sub-class (because isinstance() is far slower) + ptype = type(doc) + if ptype == dict: + return part + if ptype == list or isinstance(doc, Sequence): if part == '-': return part if not RE_ARRAY_INDEX.match(str(part)): |