Commits

Maciej Fijalkowski committed a19a489

(arigo, agaynor, fijal) a bit more precise unrolling condition

  • Participants
  • Parent commits 12f4497

Comments (0)

Files changed (1)

File pypy/objspace/std/tupleobject.py

 from pypy.rlib.debug import make_sure_not_resized
 from pypy.rlib import jit
 
+# Tuples of known length up to UNROLL_TUPLE_LIMIT have unrolled certain methods
+UNROLL_TUPLE_LIMIT = 10
+
 class W_AbstractTupleObject(W_Object):
     __slots__ = ()
 
 def mul__ANY_Tuple(space, w_times, w_tuple):
     return mul_tuple_times(space, w_tuple, w_times)
 
-@jit.look_inside_iff(lambda space, w_tuple1, w_tuple2:
-                     jit.is_constant(len(w_tuple1.wrappeditems)) and
-                     jit.is_constant(len(w_tuple2.wrappeditems)))
+def tuple_unroll_condition(space, w_tuple1, w_tuple2):
+    lgt1 = len(w_tuple1.wrappeditems)
+    lgt2 = len(w_tuple2.wrappeditems)
+    return ((jit.is_constant(lgt1) and lgt1 <= UNROLL_TUPLE_LIMIT) or
+            (jit.is_constant(lgt2) and lgt2 <= UNROLL_TUPLE_LIMIT))
+
+@jit.look_inside_iff(tuple_unroll_condition)
 def eq__Tuple_Tuple(space, w_tuple1, w_tuple2):
     items1 = w_tuple1.wrappeditems
     items2 = w_tuple2.wrappeditems
-    if len(items1) != len(items2):
+    lgt1 = len(items1)
+    lgt2 = len(items2)
+    if lgt1 != lgt2:
         return space.w_False
-    for i in range(len(items1)):
+    for i in range(lgt1):
         item1 = items1[i]
         item2 = items2[i]
         if not space.eq_w(item1, item2):
             return space.w_False
     return space.w_True
 
-@jit.look_inside_iff(lambda space, w_tuple1, w_tuple2:
-                     jit.is_constant(len(w_tuple1.wrappeditems)) and
-                     jit.is_constant(len(w_tuple2.wrappeditems)))
+@jit.look_inside_iff(tuple_unroll_condition)
 def lt__Tuple_Tuple(space, w_tuple1, w_tuple2):
     items1 = w_tuple1.wrappeditems
     items2 = w_tuple2.wrappeditems
     # No more items to compare -- compare sizes
     return space.newbool(len(items1) < len(items2))
 
-@jit.look_inside_iff(lambda space, w_tuple1, w_tuple2:
-                     jit.is_constant(len(w_tuple1.wrappeditems)) and
-                     jit.is_constant(len(w_tuple2.wrappeditems)))
+@jit.look_inside_iff(tuple_unroll_condition)
 def gt__Tuple_Tuple(space, w_tuple1, w_tuple2):
     items1 = w_tuple1.wrappeditems
     items2 = w_tuple2.wrappeditems
     return space.wrap(hash_tuple(space, w_tuple.wrappeditems))
 
 @jit.look_inside_iff(lambda space, wrappeditems:
-                     jit.is_constant(len(wrappeditems)))
+                     jit.is_constant(len(wrappeditems)) and
+                     len(wrappeditems) < UNROLL_TUPLE_LIMIT)
 def hash_tuple(space, wrappeditems):
     # this is the CPython 2.4 algorithm (changed from 2.3)
     mult = 1000003