]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Sped ._update() method by factoring try/except out of the inner loop.
authorRaymond Hettinger <python@rcn.com>
Wed, 21 Aug 2002 04:12:03 +0000 (04:12 +0000)
committerRaymond Hettinger <python@rcn.com>
Wed, 21 Aug 2002 04:12:03 +0000 (04:12 +0000)
Lib/sets.py

index 6245d5315507ae7d78b9744afe680af69bccb17f..bb4428064d1084858369b614177015cb1a3cb214 100644 (file)
@@ -280,13 +280,14 @@ class BaseSet(object):
 
     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:
+        it = iter(iterable)
+        while True:
             try:
-                data[element] = value
+                for element in it:
+                    data[element] = value
+                return
             except TypeError:
                 transform = getattr(element, "_as_immutable", None)
                 if transform is None: