[pypy-commit] pypy length-hint: add resizelist_hint
pjenvey
noreply at buildbot.pypy.org
Fri Jul 13 01:59:34 CEST 2012
Author: Philip Jenvey <pjenvey at underboss.org>
Branch: length-hint
Changeset: r56053:7ff6c6244984
Date: 2012-07-12 16:56 -0700
http://bitbucket.org/pypy/pypy/changeset/7ff6c6244984/
Log: add resizelist_hint
diff --git a/pypy/rlib/objectmodel.py b/pypy/rlib/objectmodel.py
--- a/pypy/rlib/objectmodel.py
+++ b/pypy/rlib/objectmodel.py
@@ -262,6 +262,27 @@
hop.exception_is_here()
return rtype_newlist(hop, v_sizehint=v)
+def resizelist_hint(l, sizehint):
+ """Reallocate the underlying list to the specified sizehint"""
+ return l
+
+class Entry(ExtRegistryEntry):
+ _about_ = resizelist_hint
+
+ def compute_result_annotation(self, s_l, s_sizehint):
+ from pypy.annotation.model import SomeInteger, SomeList
+ assert isinstance(s_l, SomeList)
+ assert isinstance(s_sizehint, SomeInteger)
+ s_l.listdef.listitem.resize()
+ return s_l
+
+ def specialize_call(self, hop, i_sizehint=None):
+ from pypy.rpython.lltypesystem.rlist import _ll_list_resize
+ v_list, v_sizehint = hop.inputargs(*hop.args_r)
+ hop.exception_is_here()
+ hop.llops.gendirectcall(_ll_list_resize, v_list, v_sizehint)
+ return v_list
+
# ____________________________________________________________
#
# id-like functions. The idea is that calling hash() or id() is not
diff --git a/pypy/rlib/test/test_objectmodel.py b/pypy/rlib/test/test_objectmodel.py
--- a/pypy/rlib/test/test_objectmodel.py
+++ b/pypy/rlib/test/test_objectmodel.py
@@ -465,3 +465,20 @@
break
assert llop.args[2] is graph.startblock.inputargs[0]
+def test_resizelist_hint():
+ from pypy.annotation.model import SomeInteger
+ def f(z):
+ x = []
+ resizelist_hint(x, 39)
+ if z < 0:
+ x.append(1)
+ return len(x)
+
+ graph = getgraph(f, [SomeInteger()])
+ for llop in graph.startblock.operations:
+ if llop.opname == 'direct_call':
+ break
+ call_name = llop.args[0].value._obj.graph.name
+ call_arg2 = llop.args[2].value
+ assert call_name.startswith('_ll_list_resize_really')
+ assert call_arg2 == 39
More information about the pypy-commit
mailing list