[pypy-svn] pypy default: Move pre/post -amble of hash__Tuple into a seperate function so allocations can be removed.

alex_gaynor commits-noreply at bitbucket.org
Sun May 1 21:12:55 CEST 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r43834:c1bb87039d0d
Date: 2011-05-01 15:09 -0400
http://bitbucket.org/pypy/pypy/changeset/c1bb87039d0d/

Log:	Move pre/post -amble of hash__Tuple into a seperate function so
	allocations can be removed.

diff --git a/pypy/objspace/std/tupleobject.py b/pypy/objspace/std/tupleobject.py
--- a/pypy/objspace/std/tupleobject.py
+++ b/pypy/objspace/std/tupleobject.py
@@ -88,7 +88,7 @@
     if times == 1 and space.type(w_tuple) == space.w_tuple:
         return w_tuple
     items = w_tuple.wrappeditems
-    return W_TupleObject(items * times)    
+    return W_TupleObject(items * times)
 
 def mul__Tuple_ANY(space, w_tuple, w_times):
     return mul_tuple_times(space, w_tuple, w_times)
@@ -146,17 +146,20 @@
                       + ")")
 
 def hash__Tuple(space, w_tuple):
+    return space.wrap(hash_tuple(space, w_tuple.wrappeditems))
+
+def hash_tuple(space, wrappeditems):
     # this is the CPython 2.4 algorithm (changed from 2.3)
     mult = 1000003
     x = 0x345678
-    z = len(w_tuple.wrappeditems)
-    for w_item in w_tuple.wrappeditems:
+    z = len(wrappeditems)
+    for w_item in wrappeditems:
         y = space.int_w(space.hash(w_item))
         x = (x ^ y) * mult
         z -= 1
         mult += 82520 + z + z
     x += 97531
-    return space.wrap(intmask(x))
+    return intmask(x)
 
 def getnewargs__Tuple(space, w_tuple):
     return space.newtuple([W_TupleObject(w_tuple.wrappeditems)])


More information about the Pypy-commit mailing list