Skip to content

Commit

Permalink
[refactor] Improve performance of dict flattening for board runs (#2891)
Browse files Browse the repository at this point in the history
  • Loading branch information
donderom authored Jul 5, 2023
1 parent 5abdc43 commit c158218
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions pkgs/aimstack/asp/boards/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ def memoize_query(cb, query):

@memoize
def flatten(dictionary, parent_key='', separator='.'):
items = []
flattened = {}
for key, value in dictionary.items():
new_key = parent_key + separator + key if parent_key else key
new_key = f"{parent_key}{separator}{key}" if parent_key else key
if isinstance(value, MutableMapping):
items.extend(flatten(value, new_key, separator=separator).items())
flattened.update(flatten(value, new_key, separator=separator))
else:
items.append((new_key, value))
return dict(items)
flattened[new_key] = value
return flattened


@memoize
Expand Down
10 changes: 5 additions & 5 deletions pkgs/aimstack/asp/boards/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@


def flatten(dictionary, parent_key='', separator='.'):
items = []
flattened = {}
for key, value in dictionary.items():
new_key = parent_key + separator + key if parent_key else key
new_key = f"{parent_key}{separator}{key}" if parent_key else key
if isinstance(value, MutableMapping):
items.extend(flatten(value, new_key, separator=separator).items())
flattened.update(flatten(value, new_key, separator=separator))
else:
items.append((new_key, value))
return dict(items)
flattened[new_key] = value
return flattened


@memoize
Expand Down

0 comments on commit c158218

Please sign in to comment.