Skip to content

Commit c4372cd

Browse files
committed
Optimize in get_part for the common cases of doc being dict or list
1 parent 76b542b commit c4372cd

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

jsonpointer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,12 @@ def set(self, doc, value, inplace=True):
196196
def get_part(self, doc, part):
197197
""" Returns the next step in the correct type """
198198

199-
if isinstance(doc, Sequence):
199+
# Optimize for common cases of doc being a dict or list, but not a
200+
# sub-class (because isinstance() is far slower)
201+
ptype = type(doc)
202+
if ptype == dict:
203+
return part
204+
if ptype == list or isinstance(doc, Sequence):
200205
if part == '-':
201206
return part
202207
if not RE_ARRAY_INDEX.match(str(part)):

0 commit comments

Comments
 (0)