Skip to content

Commit

Permalink
perf: Refactor iter_cell_list_contents (projectmesa#1527)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tortar authored Nov 16, 2022
1 parent 0629140 commit bd26c2f
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions mesa/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,8 @@ def iter_cell_list_contents(
Returns:
An iterator of the contents of the cells identified in cell_list
"""
# Note: filter(None, iterator) filters away an element of iterator that
# is falsy. Hence, iter_cell_list_contents returns only non-empty
# contents.
return filter(None, (self.grid[x][y] for x, y in cell_list))
# iter_cell_list_contents returns only non-empty contents.
return (self.grid[x][y] for x, y in cell_list if self.grid[x][y])

@accept_tuple_argument
def get_cell_list_contents(self, cell_list: Iterable[Coordinate]) -> list[Agent]:
Expand Down

0 comments on commit bd26c2f

Please sign in to comment.