summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jsonpointer.py7
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)):