Author: Lukas Diekmann <[email protected]>
Branch: set-strategies
Changeset: r49262:fca421c60d1d
Date: 2011-11-03 16:14 +0100
http://bitbucket.org/pypy/pypy/changeset/fca421c60d1d/
Log: added fastpath to intersection and fixed not_contain_equal_elements
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
@@ -578,6 +578,9 @@
if self is w_other.strategy:
strategy = w_set.strategy
storage = strategy._intersect_unwrapped(w_set, w_other)
+ elif not_contain_equal_elements(self.space, w_set, w_other):
+ strategy = self.space.fromcache(EmptySetStrategy)
+ storage = strategy.get_empty_storage()
else:
strategy = self.space.fromcache(ObjectSetStrategy)
storage = self._intersect_wrapped(w_set, w_other)
@@ -893,11 +896,16 @@
# some helper functions
def not_contain_equal_elements(space, w_set, w_other):
+ # add strategies here for which elements from sets with theses strategies
are never equal.
+
strategy1 = w_set.strategy
strategy2 = w_other.strategy
- # add strategies here for which elements from sets with theses strategies
are never equal.
+
if strategy1 is space.fromcache(StringSetStrategy) and strategy2 is
space.fromcache(IntegerSetStrategy):
return True
+ if strategy1 is space.fromcache(IntegerSetStrategy) and strategy2 is
space.fromcache(StringSetStrategy):
+ return True
+
if strategy1 is space.fromcache(EmptySetStrategy) or strategy2 is
space.fromcache(EmptySetStrategy):
# an empty set and another set will never have any equal element
return True
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
@@ -604,12 +604,17 @@
x.symmetric_difference_update(set())
assert x == set([1,2,3])
- def test_difference_uncomparable_strategies(self):
+ def test_fastpath_with_strategies(self):
a = set([1,2,3])
b = set(["a","b","c"])
assert a.difference(b) == a
assert b.difference(a) == b
+ a = set([1,2,3])
+ b = set(["a","b","c"])
+ assert a.intersection(b) == set()
+ assert b.intersection(a) == set()
+
def test_empty_intersect(self):
e = set()
x = set([1,2,3])
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit