Skip to content

Commit

Permalink
Micro-optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Apr 24, 2015
1 parent 5758557 commit b42a65c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions transaction/weakset.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,12 @@ def map(self, f):
# elements are actually trash. By returning a list of weakrefs instead,
# we avoid that, although the decision to use weakrefs is now very
# visible to our clients.
def as_weakref_list(self):
if PY3: #pragma: no cover (coverage tests run under 2.7)
# Python 3: be sure to freeze the iterator, to avoid RuntimeError:
# dictionary changed size during iteration.
def as_weakref_list(self):
return list(self.data.valuerefs())
else:
# On Python2 we already get a list, no need to copy
refs = self.data.valuerefs()
return list(refs) if PY3 else refs
def as_weakref_list(self):
return self.data.valuerefs()

0 comments on commit b42a65c

Please sign in to comment.