[pypy-svn] r40199 - pypy/dist/pypy/objspace/std
arigo at codespeak.net
arigo at codespeak.net
Sun Mar 11 13:00:23 CET 2007
Author: arigo
Date: Sun Mar 11 13:00:22 2007
New Revision: 40199
Modified:
pypy/dist/pypy/objspace/std/inttype.py
Log:
A pair of tricks that seem to help prebuiltint a bit:
* use r_uint to do a single comparison instead of two
* store the 'intval' in all cases, to avoid cache misses
the next time it is read
Modified: pypy/dist/pypy/objspace/std/inttype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/inttype.py (original)
+++ pypy/dist/pypy/objspace/std/inttype.py Sun Mar 11 13:00:22 2007
@@ -2,6 +2,8 @@
from pypy.objspace.std.strutil import string_to_int, string_to_w_long, ParseStringError, ParseStringOverflowError
from pypy.interpreter.error import OperationError
from pypy.interpreter.gateway import NoneNotWrapped
+from pypy.rlib.rarithmetic import r_uint
+from pypy.rlib.objectmodel import instantiate
# ____________________________________________________________
@@ -18,11 +20,13 @@
from pypy.objspace.std.intobject import W_IntObject
lower = space.config.objspace.std.prebuiltintfrom
upper = space.config.objspace.std.prebuiltintto
- index = x - lower
- if 0 <= index < upper - lower:
- return W_IntObject.PREBUILT[index]
+ index = r_uint(x - lower)
+ if index >= r_uint(upper - lower):
+ w_res = instantiate(W_IntObject)
else:
- return W_IntObject(x)
+ w_res = W_IntObject.PREBUILT[index]
+ w_res.intval = x
+ return w_res
else:
from pypy.objspace.std.intobject import W_IntObject
return W_IntObject(x)
More information about the Pypy-commit
mailing list