[pypy-commit] pypy default: Some set speedups

fijal noreply at buildbot.pypy.org
Mon Jul 1 09:15:26 CEST 2013


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: 
Changeset: r65134:8a241c817172
Date: 2013-07-01 09:14 +0200
http://bitbucket.org/pypy/pypy/changeset/8a241c817172/

Log:	Some set speedups

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
@@ -941,7 +941,12 @@
     def equals(self, w_set, w_other):
         if w_set.length() != w_other.length():
             return False
+        if w_set.length() == 0:
+            return True
+        # it's possible to have 0-lenght strategy that's not empty
         items = self.unerase(w_set.sstorage).keys()
+        if not self.may_contain_equal_elements(w_other.strategy):
+            return False
         for key in items:
             if not w_other.has_key(self.wrap(key)):
                 return False
@@ -1210,7 +1215,9 @@
     def may_contain_equal_elements(self, strategy):
         if strategy is self.space.fromcache(IntegerSetStrategy):
             return False
-        if strategy is self.space.fromcache(EmptySetStrategy):
+        elif strategy is self.space.fromcache(EmptySetStrategy):
+            return False
+        elif strategy is self.space.fromcache(IdentitySetStrategy):
             return False
         return True
 
@@ -1244,7 +1251,9 @@
     def may_contain_equal_elements(self, strategy):
         if strategy is self.space.fromcache(IntegerSetStrategy):
             return False
-        if strategy is self.space.fromcache(EmptySetStrategy):
+        elif strategy is self.space.fromcache(EmptySetStrategy):
+            return False
+        elif strategy is self.space.fromcache(IdentitySetStrategy):
             return False
         return True
 
@@ -1278,9 +1287,11 @@
     def may_contain_equal_elements(self, strategy):
         if strategy is self.space.fromcache(StringSetStrategy):
             return False
-        if strategy is self.space.fromcache(UnicodeSetStrategy):
+        elif strategy is self.space.fromcache(UnicodeSetStrategy):
             return False
-        if strategy is self.space.fromcache(EmptySetStrategy):
+        elif strategy is self.space.fromcache(EmptySetStrategy):
+            return False
+        elif strategy is self.space.fromcache(IdentitySetStrategy):
             return False
         return True
 
@@ -1342,7 +1353,7 @@
     erase, unerase = rerased.new_erasing_pair("identityset")
     erase = staticmethod(erase)
     unerase = staticmethod(unerase)
-    
+
     def get_empty_storage(self):
         return self.erase({})
 
@@ -1369,10 +1380,10 @@
         return w_item
 
     def wrap(self, item):
-        return item    
-    
+        return item
+
     def iter(self, w_set):
-        return IdentityIteratorImplementation(self.space, self, w_set)        
+        return IdentityIteratorImplementation(self.space, self, w_set)
 
 class IteratorImplementation(object):
     def __init__(self, space, strategy, implementation):
@@ -1593,7 +1604,7 @@
         w_set.strategy = space.fromcache(UnicodeSetStrategy)
         w_set.sstorage = w_set.strategy.get_storage_from_list(iterable_w)
         return
-    
+
     # check for compares by identity
     for w_item in iterable_w:
         if not space.type(w_item).compares_by_identity():
@@ -1601,7 +1612,7 @@
     else:
         w_set.strategy = space.fromcache(IdentitySetStrategy)
         w_set.sstorage = w_set.strategy.get_storage_from_list(iterable_w)
-        return    
+        return
 
     w_set.strategy = space.fromcache(ObjectSetStrategy)
     w_set.sstorage = w_set.strategy.get_storage_from_list(iterable_w)


More information about the pypy-commit mailing list