Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 80d21af

Browse files
committed
Sped ._update() method by factoring try/except out of the inner loop.
1 parent 9f87293 commit 80d21af

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

Lib/sets.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,14 @@ def _compute_hash(self):
280280

281281
def _update(self, iterable):
282282
# The main loop for update() and the subclass __init__() methods.
283-
# XXX This can be optimized a bit by first trying the loop
284-
# without setting up a try/except for each element.
285283
data = self._data
286284
value = True
287-
for element in iterable:
285+
it = iter(iterable)
286+
while True:
288287
try:
289-
data[element] = value
288+
for element in it:
289+
data[element] = value
290+
return
290291
except TypeError:
291292
transform = getattr(element, "_as_immutable", None)
292293
if transform is None:

0 commit comments

Comments
 (0)