diff options
author | Raymond Hettinger <python@rcn.com> | 2002-08-21 04:12:03 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2002-08-21 04:12:03 (GMT) |
commit | 80d21af614038a3163b1def661a5087735865395 (patch) | |
tree | 76969c2cd86f0808cd324b3f0ded55255fcddb84 /Lib | |
parent | 9f87293bf533eb3ac7f770b3bbe1fdf82e7118fb (diff) | |
download | cpython-80d21af614038a3163b1def661a5087735865395.zip cpython-80d21af614038a3163b1def661a5087735865395.tar.gz cpython-80d21af614038a3163b1def661a5087735865395.tar.bz2 |
Sped ._update() method by factoring try/except out of the inner loop.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/sets.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/Lib/sets.py b/Lib/sets.py index 6245d53..bb44280 100644 --- a/Lib/sets.py +++ b/Lib/sets.py @@ -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: |