[pypy-svn] r24362 - in pypy/dist/pypy: interpreter module/__builtin__ translator
ac at codespeak.net
ac at codespeak.net
Tue Mar 14 17:19:56 CET 2006
Author: ac
Date: Tue Mar 14 17:19:55 2006
New Revision: 24362
Modified:
pypy/dist/pypy/interpreter/baseobjspace.py
pypy/dist/pypy/interpreter/mixedmodule.py
pypy/dist/pypy/interpreter/module.py
pypy/dist/pypy/interpreter/pycode.py
pypy/dist/pypy/module/__builtin__/__init__.py
pypy/dist/pypy/module/__builtin__/app_misc.py
pypy/dist/pypy/module/__builtin__/operation.py
pypy/dist/pypy/translator/geninterplevel.py
Log:
(pedronis, arre)
Create a space helper for interning strings and use it for names, mostly
in code objects. => Slight performace improvement in pystone and richards.
Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py (original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py Tue Mar 14 17:19:55 2006
@@ -127,6 +127,7 @@
self.options.usemodules = usemodules
self.options.translating = translating
self.options.geninterp = geninterp
+ self.interned_strings = {}
self.setoptions(**kw)
self.initialize()
@@ -376,6 +377,14 @@
else:
return self.w_False
+ def new_interned_str(self, s):
+ try:
+ return self.interned_strings[s]
+ except KeyError:
+ pass
+ w_s = self.interned_strings[s] = self.wrap(s)
+ return w_s
+
# support for the deprecated __getslice__, __setslice__, __delslice__
def getslice(self, w_obj, w_start, w_stop):
w_slice = self.newslice(w_start, w_stop, self.w_None)
Modified: pypy/dist/pypy/interpreter/mixedmodule.py
==============================================================================
--- pypy/dist/pypy/interpreter/mixedmodule.py (original)
+++ pypy/dist/pypy/interpreter/mixedmodule.py Tue Mar 14 17:19:55 2006
@@ -30,8 +30,9 @@
w_builtin = self.get(name)
return self.space.call_function(w_builtin, *args_w)
- def getdictvalue(self, space, name):
- w_value = space.finditem(self.w_dict, space.wrap(name))
+ def getdictvalue(self, space, name):
+ w_name = space.new_interned_str(name)
+ w_value = space.finditem(self.w_dict, w_name)
if self.lazy and w_value is None:
try:
loader = self.loaders[name]
@@ -51,7 +52,7 @@
bltin.w_module = self.w_name
func._builtinversion_ = bltin
w_value = space.wrap(bltin)
- space.setitem(self.w_dict, space.wrap(name), w_value)
+ space.setitem(self.w_dict, w_name, w_value)
return w_value
def getdict(self):
@@ -59,7 +60,7 @@
space = self.space
for name in self.loaders:
w_value = self.get(name)
- space.setitem(self.w_dict, space.wrap(name), w_value)
+ space.setitem(self.w_dict, space.new_interned_str(name), w_value)
self.lazy = False
return self.w_dict
Modified: pypy/dist/pypy/interpreter/module.py
==============================================================================
--- pypy/dist/pypy/interpreter/module.py (original)
+++ pypy/dist/pypy/interpreter/module.py Tue Mar 14 17:19:55 2006
@@ -14,7 +14,7 @@
self.w_dict = w_dict
self.w_name = w_name
if w_name is not None:
- space.setitem(w_dict, space.wrap('__name__'), w_name)
+ space.setitem(w_dict, space.new_interned_str('__name__'), w_name)
def setup_after_space_initialization(self):
"""NOT_RPYTHON: to allow built-in modules to do some more setup
@@ -33,5 +33,5 @@
self.w_name = w_name
if w_doc is None:
w_doc = space.w_None
- space.setitem(self.w_dict, space.wrap('__name__'), w_name)
- space.setitem(self.w_dict, space.wrap('__doc__'), w_doc)
+ space.setitem(self.w_dict, space.new_interned_str('__name__'), w_name)
+ space.setitem(self.w_dict, space.new_interned_str('__doc__'), w_doc)
Modified: pypy/dist/pypy/interpreter/pycode.py
==============================================================================
--- pypy/dist/pypy/interpreter/pycode.py (original)
+++ pypy/dist/pypy/interpreter/pycode.py Tue Mar 14 17:19:55 2006
@@ -95,7 +95,7 @@
self.co_flags = flags
self.co_code = code
self.co_consts_w = consts
- self.co_names_w = [space.wrap(aname) for aname in names]
+ self.co_names_w = [space.new_interned_str(aname) for aname in names]
self.co_varnames = varnames
self.co_freevars = freevars
self.co_cellvars = cellvars
Modified: pypy/dist/pypy/module/__builtin__/__init__.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/__init__.py (original)
+++ pypy/dist/pypy/module/__builtin__/__init__.py Tue Mar 14 17:19:55 2006
@@ -50,7 +50,6 @@
'complex' : 'app_complex.complex',
- 'intern' : 'app_misc.intern',
'buffer' : 'app_buffer.buffer',
'reload' : 'app_misc.reload',
@@ -105,6 +104,7 @@
'hash' : 'operation.hash',
'id' : 'operation.id',
'_seqiter' : 'operation._seqiter',
+ 'intern' : 'operation.intern',
'compile' : 'compiling.compile',
'eval' : 'compiling.eval',
@@ -112,7 +112,6 @@
'__import__' : 'importing.importhook',
'range' : 'functional.range_int',
-
# float->string helper
'_formatd' : 'special._formatd'
}
Modified: pypy/dist/pypy/module/__builtin__/app_misc.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/app_misc.py (original)
+++ pypy/dist/pypy/module/__builtin__/app_misc.py Tue Mar 14 17:19:55 2006
@@ -3,13 +3,6 @@
"""
-_stringtable = {}
-def intern(s):
- # XXX CPython has also non-immortal interned strings
- if not type(s) is str:
- raise TypeError("intern() argument 1 must be string.")
- return _stringtable.setdefault(s,s)
-
def find_module(fullname, path):
import sys
meta_path = sys.meta_path
Modified: pypy/dist/pypy/module/__builtin__/operation.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/operation.py (original)
+++ pypy/dist/pypy/module/__builtin__/operation.py Tue Mar 14 17:19:55 2006
@@ -159,3 +159,8 @@
def setattr(space, w_object, w_name, w_val):
space.setattr(w_object, w_name, w_val)
return space.w_None
+
+def intern(space, w_str):
+ if space.is_w(space.type(w_str), space.w_str):
+ return space.new_interned_str(space.str_w(w_str))
+ raise OperationError(space.w_TypeError, space.wrap("intern() argument 1 must be string."))
Modified: pypy/dist/pypy/translator/geninterplevel.py
==============================================================================
--- pypy/dist/pypy/translator/geninterplevel.py (original)
+++ pypy/dist/pypy/translator/geninterplevel.py Tue Mar 14 17:19:55 2006
@@ -560,9 +560,9 @@
namestr = "_emptystr_"
name = self.uniquename('gs_' + namestr[:32])
if len(value) < 30 and "\n" not in value:
- txt = '%s = space.wrap(%r)' % (name, value)
+ txt = '%s = space.new_interned_str(%r)' % (name, value)
else:
- txt = render_docstr(value, '%s = space.wrap(\n' % name, ')')
+ txt = render_docstr(value, '%s = space.new_interned_str(\n' % name, ')')
txt = txt, # not splitted
self.initcode.append(txt)
return name
@@ -939,11 +939,11 @@
# property is lazy loaded app-level as well, trigger it*s creation
self.initcode.append1('space.builtin.get("property") # pull it in')
globname = self.nameof(self.moddict)
- self.initcode.append('space.setitem(%s, space.wrap("__builtins__"), '
+ self.initcode.append('space.setitem(%s, space.new_interned_str("__builtins__"), '
'space.builtin.w_dict)' % globname)
self.initcode.append('%s = space.eval("property(%s)", %s, %s)' %(
name, origin, globname, globname) )
- self.initcode.append('space.delitem(%s, space.wrap("__builtins__"))'
+ self.initcode.append('space.delitem(%s, space.new_interned_str("__builtins__"))'
% globname)
return name
@@ -1039,7 +1039,7 @@
# make sure it is not rendered again
key = Constant(doc).key
self.rpynames[key] = "w__doc__"
- self.initcode.append("w__doc__ = space.wrap(__doc__)")
+ self.initcode.append("w__doc__ = space.new_interned_str(__doc__)")
# info.entrypoint must be done *after* __doc__ is handled,
# because nameof(entrypoint) might touch __doc__ early.
More information about the Pypy-commit
mailing list