[Python-checkins] python/dist/src/Lib sets.py,1.10,1.11
rhettinger@users.sourceforge.net
rhettinger@users.sourceforge.net
Tue, 20 Aug 2002 21:12:07 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv7435
Modified Files:
sets.py
Log Message:
Sped ._update() method by factoring try/except out of the inner loop.
Index: sets.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sets.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** sets.py 21 Aug 2002 03:20:44 -0000 1.10
--- sets.py 21 Aug 2002 04:12:03 -0000 1.11
***************
*** 281,291 ****
def _update(self, iterable):
# 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
value = True
! for element in iterable:
try:
! data[element] = value
except TypeError:
transform = getattr(element, "_as_immutable", None)
--- 281,292 ----
def _update(self, iterable):
# The main loop for update() and the subclass __init__() methods.
data = self._data
value = True
! it = iter(iterable)
! while True:
try:
! for element in it:
! data[element] = value
! return
except TypeError:
transform = getattr(element, "_as_immutable", None)