[pypy-commit] pypy set-strategies: create set from iterable to check length and use fastpath
l.diekmann
noreply at buildbot.pypy.org
Thu Nov 10 13:51:13 CET 2011
Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: set-strategies
Changeset: r49201:541a226d5845
Date: 2011-08-23 14:19 +0200
http://bitbucket.org/pypy/pypy/changeset/541a226d5845/
Log: create set from iterable to check length and use fastpath
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
@@ -520,7 +520,9 @@
w_set.sstorage = result.sstorage
def issuperset(self, w_set, w_other):
- #XXX always True if other is empty
+ if w_other.length() == 0:
+ return True
+
w_iter = self.space.iter(w_other)
while True:
try:
@@ -965,7 +967,11 @@
if space.is_w(w_left, w_other):
return space.w_True
- return space.wrap(w_left.issuperset(w_other))
+ w_other_as_set = w_left._newobj(space, w_other)
+
+ if w_left.length() < w_other_as_set.length():
+ return space.w_False
+ return space.wrap(w_left.issuperset(w_other_as_set))
frozenset_issuperset__Frozenset_ANY = set_issuperset__Set_ANY
diff --git a/pypy/objspace/std/test/test_setobject.py b/pypy/objspace/std/test/test_setobject.py
--- a/pypy/objspace/std/test/test_setobject.py
+++ b/pypy/objspace/std/test/test_setobject.py
@@ -611,6 +611,12 @@
yield i
set([1,2,3,4,5]).issuperset(foo())
+ def test_isdisjoint_with_generator(self):
+ def foo():
+ for i in [1,2,3]:
+ yield i
+ set([1,2,3,4,5]).isdisjoint(foo())
+
def test_fakeint_and_equals(self):
s1 = set([1,2,3,4])
s2 = set([1,2,self.FakeInt(3), 4])
More information about the pypy-commit
mailing list