[pypy-svn] r30660 - in pypy/dist/pypy/translator/cli: . test
antocuni at codespeak.net
antocuni at codespeak.net
Fri Jul 28 00:19:48 CEST 2006
Author: antocuni
Date: Fri Jul 28 00:19:29 2006
New Revision: 30660
Modified:
pypy/dist/pypy/translator/cli/database.py
pypy/dist/pypy/translator/cli/test/test_constant.py
Log:
oops... the pending_function modify was forgotten from previous checkin.
Simple optimization for constant list of zeroes: it sufficient to only
resize them to the correct size, because the default value is already
zero.
Modified: pypy/dist/pypy/translator/cli/database.py
==============================================================================
--- pypy/dist/pypy/translator/cli/database.py (original)
+++ pypy/dist/pypy/translator/cli/database.py Fri Jul 28 00:19:29 2006
@@ -83,8 +83,11 @@
else:
return None, parts[0]
- def pending_function(self, graph):
- function = self.function_class(self, graph)
+ def pending_function(self, graph, functype=None):
+ if functype is None:
+ function = self.function_class(self, graph)
+ else:
+ function = functype(self, graph)
self.pending_node(function)
return function.get_name()
@@ -461,6 +464,12 @@
class_name = self.get_type(False)
ilasm.new('instance void class %s::.ctor()' % class_name)
+ def _list_of_zeroes(self):
+ try:
+ return self.value._list == [0] * len(self.value._list)
+ except:
+ return False
+
def init(self, ilasm):
assert not self.is_null()
ITEMTYPE = self.value._TYPE._ITEMTYPE
@@ -468,9 +477,10 @@
itemtype_T = self.cts.lltype_to_cts(self.value._TYPE.ITEMTYPE_T)
# special case: List(Void); only resize it, don't care of the contents
- if ITEMTYPE is ootype.Void:
+ # special case: list of zeroes, don't need to initialize every item
+ if ITEMTYPE is ootype.Void or self._list_of_zeroes():
AbstractConst.load(self.db, ootype.Signed, len(self.value._list), ilasm)
- meth = 'void class %s::_ll_resize(int32)' % PYPY_LIST_OF_VOID
+ meth = 'void class %s::_ll_resize(int32)' % self.get_type(False) #PYPY_LIST_OF_VOID
ilasm.call_method(meth, False)
return
Modified: pypy/dist/pypy/translator/cli/test/test_constant.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_constant.py (original)
+++ pypy/dist/pypy/translator/cli/test/test_constant.py Fri Jul 28 00:19:29 2006
@@ -47,6 +47,13 @@
res = self.interpret(fn, [])
assert self.class_name(res) == 'A'
+ def test_list_of_zeroes(self):
+ const = [0] * 10
+ def fn():
+ return const
+ res = self.ll_to_list(self.interpret(fn, []))
+ assert res == const
+
def test_list_of_instances(self):
const = [A()]
def fn():
More information about the Pypy-commit
mailing list