[pypy-svn] r40427 - pypy/dist/pypy/objspace/std
arigo at codespeak.net
arigo at codespeak.net
Tue Mar 13 11:43:53 CET 2007
Author: arigo
Date: Tue Mar 13 11:43:51 2007
New Revision: 40427
Modified:
pypy/dist/pypy/objspace/std/typeobject.py
Log:
Improve the hash function used by the method cache.
Seems to give good speed-ups on some of our benchmarks.
Modified: pypy/dist/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/typeobject.py (original)
+++ pypy/dist/pypy/objspace/std/typeobject.py Tue Mar 13 11:43:51 2007
@@ -7,6 +7,7 @@
from pypy.objspace.std.objecttype import object_typedef
from pypy.objspace.std.dictproxyobject import W_DictProxyObject
from pypy.rlib.objectmodel import we_are_translated
+from pypy.rlib.rarithmetic import intmask, r_uint
from copy_reg import _HEAPTYPE
@@ -312,18 +313,12 @@
space = w_self.space
assert space.config.objspace.std.withmethodcache
ec = space.getexecutioncontext()
- #try:
- # frame = ec.framestack.top()
- # position_hash = frame.last_instr ^ id(frame.pycode)
- #except IndexError:
- # position_hash = 0
version_tag = w_self.version_tag
if version_tag is None:
tup = w_self._lookup_where(name)
return tup
- MASK = (1 << space.config.objspace.std.methodcachesizeexp) - 1
- #method_hash = (id(version_tag) ^ position_hash ^ hash(name)) & MASK
- method_hash = ((id(version_tag) >> 3) ^ hash(name)) & MASK
+ SHIFT = r_uint.BITS - space.config.objspace.std.methodcachesizeexp
+ method_hash = r_uint(intmask(id(version_tag) * hash(name))) >> SHIFT
cached_version_tag = ec.method_cache_versions[method_hash]
if cached_version_tag is version_tag:
cached_name = ec.method_cache_names[method_hash]
More information about the Pypy-commit
mailing list