[pypy-commit] pypy set-strategies: replaced getkeys in hash_FrozenSet with iterator

l.diekmann noreply at buildbot.pypy.org
Thu Nov 10 13:51:49 CET 2011


Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: set-strategies
Changeset: r49232:973765c2af6d
Date: 2011-10-12 14:14 +0200
http://bitbucket.org/pypy/pypy/changeset/973765c2af6d/

Log:	replaced getkeys in hash_FrozenSet with iterator

diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py
--- a/pypy/objspace/std/setobject.py
+++ b/pypy/objspace/std/setobject.py
@@ -1050,10 +1050,17 @@
         return space.wrap(w_set.hash)
     hash = 1927868237
     hash *= (w_set.length() + 1)
-    for w_item in w_set.getkeys():
-        h = space.hash_w(w_item)
-        value = ((h ^ (h << 16) ^ 89869747)  * multi)
-        hash = intmask(hash ^ value)
+    w_iterator = space.iter(w_set)
+    while True:
+        try:
+            w_item = space.next(w_iterator)
+            h = space.hash_w(w_item)
+            value = ((h ^ (h << 16) ^ 89869747)  * multi)
+            hash = intmask(hash ^ value)
+        except OperationError, e:
+            if not e.match(space, space.w_StopIteration):
+                raise
+            break
     hash = hash * 69069 + 907133923
     if hash == 0:
         hash = 590923713


More information about the pypy-commit mailing list