Skip to content

Commit

Permalink
minor performance optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
jjtolton committed Nov 11, 2017
1 parent 574031d commit 26b64a1
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions naga/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,13 +556,18 @@ def update_in(d, key_list, fn, *args, **kwargs):


def dispatch(x, dispatch_table=None):
Table = dispatch_table or (fpartial(isinstance, collections.MutableMapping), Dict,
fpartial(isinstance, str), String,
fpartial(isinstance, list), List,
fpartial(isinstance, tuple), Tuple,
lambda _: True, type(x))

return cond(x, *Table)
Table = {dict: lambda: Dict,
list: lambda: List,
str: lambda: String,
tuple: lambda: Tuple}

Lookup = dispatch_table or (fpartial(isinstance, collections.MutableMapping), Dict,
fpartial(isinstance, str), String,
fpartial(isinstance, list), List,
fpartial(isinstance, tuple), Tuple,
lambda _: True, type(x))

return Table.get(type(x), lambda: cond(x, *Lookup))()


def recursive_dict_merge(*ds):
Expand Down

0 comments on commit 26b64a1

Please sign in to comment.