[pypy-svn] r29411 - pypy/dist/pypy/objspace/std
arigo at codespeak.net
arigo at codespeak.net
Tue Jun 27 19:12:39 CEST 2006
Author: arigo
Date: Tue Jun 27 19:12:36 2006
New Revision: 29411
Modified:
pypy/dist/pypy/objspace/std/intobject.py
pypy/dist/pypy/objspace/std/inttype.py
pypy/dist/pypy/objspace/std/model.py
Log:
Support for prebuilt W_IntObjects for common integers values, as in
CPython. Disabled by default. Only for the case where WITHSMALLINT ==
False.
I will compare the speed benefits of this with the speed benefits of
WITHSMALLINT. The latter gives around 6-10% in Pystone.
Modified: pypy/dist/pypy/objspace/std/intobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/intobject.py (original)
+++ pypy/dist/pypy/objspace/std/intobject.py Tue Jun 27 19:12:36 2006
@@ -26,6 +26,18 @@
registerimplementation(W_IntObject)
+# ____________________________________________________________
+# Prebuilt common integer values
+
+from pypy.objspace.std.model import WITHPREBUILTINT
+if WITHPREBUILTINT:
+ W_IntObject.PREBUILT = []
+ for i in WITHPREBUILTINT:
+ W_IntObject.PREBUILT.append(W_IntObject(i))
+ del i
+
+# ____________________________________________________________
+
"""
XXX not implemented:
Modified: pypy/dist/pypy/objspace/std/inttype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/inttype.py (original)
+++ pypy/dist/pypy/objspace/std/inttype.py Tue Jun 27 19:12:36 2006
@@ -5,7 +5,8 @@
# ____________________________________________________________
-from pypy.objspace.std.model import WITHSMALLINT
+from pypy.objspace.std.model import WITHSMALLINT, WITHPREBUILTINT
+
if WITHSMALLINT:
def wrapint(x):
from pypy.objspace.std.smallintobject import W_SmallIntObject
@@ -14,6 +15,20 @@
except OverflowError:
from pypy.objspace.std.intobject import W_IntObject
return W_IntObject(x)
+
+elif WITHPREBUILTINT:
+ PREBUILT_RANGE_START = WITHPREBUILTINT[0]
+ PREBUILT_RANGE_LEN = len(WITHPREBUILTINT)
+ assert WITHPREBUILTINT == range(PREBUILT_RANGE_START,
+ PREBUILT_RANGE_START + PREBUILT_RANGE_LEN)
+ def wrapint(x):
+ from pypy.objspace.std.intobject import W_IntObject
+ index = x - PREBUILT_RANGE_START
+ if 0 <= index < PREBUILT_RANGE_LEN:
+ return W_IntObject.PREBUILT[index]
+ else:
+ return W_IntObject(x)
+
else:
def wrapint(x):
from pypy.objspace.std.intobject import W_IntObject
Modified: pypy/dist/pypy/objspace/std/model.py
==============================================================================
--- pypy/dist/pypy/objspace/std/model.py (original)
+++ pypy/dist/pypy/objspace/std/model.py Tue Jun 27 19:12:36 2006
@@ -9,6 +9,7 @@
import pypy.interpreter.special
WITHSMALLINT = False
+WITHPREBUILTINT = None # or e.g. range(-5, 100); not used if WITHSMALLINT
WITHSTRSLICE = False
class StdTypeModel:
More information about the Pypy-commit
mailing list