mirror of
https://github.com/python/cpython.git
synced 2025-12-04 16:43:27 +00:00
Sped ._update() method by factoring try/except out of the inner loop.
This commit is contained in:
parent
9f87293bf5
commit
80d21af614
1 changed files with 5 additions and 4 deletions
|
|
@ -280,13 +280,14 @@ class BaseSet(object):
|
||||||
|
|
||||||
def _update(self, iterable):
|
def _update(self, iterable):
|
||||||
# The main loop for update() and the subclass __init__() methods.
|
# The main loop for update() and the subclass __init__() methods.
|
||||||
# XXX This can be optimized a bit by first trying the loop
|
|
||||||
# without setting up a try/except for each element.
|
|
||||||
data = self._data
|
data = self._data
|
||||||
value = True
|
value = True
|
||||||
for element in iterable:
|
it = iter(iterable)
|
||||||
|
while True:
|
||||||
try:
|
try:
|
||||||
|
for element in it:
|
||||||
data[element] = value
|
data[element] = value
|
||||||
|
return
|
||||||
except TypeError:
|
except TypeError:
|
||||||
transform = getattr(element, "_as_immutable", None)
|
transform = getattr(element, "_as_immutable", None)
|
||||||
if transform is None:
|
if transform is None:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue