[pypy-svn] pypy default: Optimise set.__lt__: if sizes are equal, no need to test anything

amauryfa commits-noreply at bitbucket.org
Tue Jan 25 18:05:57 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r41324:857ec1e4617d
Date: 2011-01-25 13:42 +0100
http://bitbucket.org/pypy/pypy/changeset/857ec1e4617d/

Log:	Optimise set.__lt__: if sizes are equal, no need to test anything

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
@@ -388,7 +388,7 @@
 # automatic registration of "lt(x, y)" as "not ge(y, x)" would not give the
 # correct answer here!
 def lt__Set_Set(space, w_left, w_other):
-    if _is_eq(w_left.setdata, w_other.setdata):
+    if len(w_left.setdata) >= len(w_other.setdata):
         return space.w_False
     else:
         return le__Set_Set(space, w_left, w_other)
@@ -398,7 +398,7 @@
 lt__Frozenset_Frozenset = lt__Set_Set
 
 def gt__Set_Set(space, w_left, w_other):
-    if _is_eq(w_left.setdata, w_other.setdata):
+    if len(w_left.setdata) <= len(w_other.setdata):
         return space.w_False
     else:
         return ge__Set_Set(space, w_left, w_other)


More information about the Pypy-commit mailing list