Commits

Armin Rigo committed b02477f

(fijal, arigo)
Kill the objectmodel.newlist(sizehint=...) operation.
It was not used at all, so it's decluttering.

Comments (0)

Files changed (6)

pypy/rlib/objectmodel.py

         self.dic = dic
         self.key = key
         self.hash = hash
-
-# ------------------------- optimization hints ------------------------------
-
-def newlist(sizehint=0):
-    return []
-
-class Entry(ExtRegistryEntry):
-    _about_ = newlist
-
-    def compute_result_annotation(self, s_sizehint):
-        return self.bookkeeper.newlist()
-
-    def specialize_call(self, orig_hop, i_sizehint=None):
-        from pypy.rpython.rlist import rtype_newlist
-        from pypy.rpython.lltypesystem import lltype
-        # fish a bit hop
-        hop = orig_hop.copy()
-        v = hop.args_v[0]
-        r, s = hop.r_s_popfirstarg()
-        if s.is_constant():
-            v = hop.inputconst(r, s.const)
-        return rtype_newlist(hop, v_sizehint=v)

pypy/rlib/test/test_objectmodel.py

     if option.view:
         graph.show()
     return graph
-
-def test_newlist():
-    from pypy.annotation.model import SomeInteger
-    def f(z):
-        x = newlist(sizehint=38)
-        if z < 0:
-            x.append(1)
-        return len(x)
-
-    graph = getgraph(f, [SomeInteger()])
-    for llop in graph.startblock.operations:
-        if llop.opname == 'malloc_varsize':
-            break
-    assert llop.args[2].value == 38
-
-def test_newlist_nonconst():
-    from pypy.annotation.model import SomeInteger
-    from pypy.objspace.flow.model import Variable
-    def f(z):
-        x = newlist(sizehint=z)
-        return len(x)
-
-    graph = getgraph(f, [SomeInteger()])
-    for llop in graph.startblock.operations:
-        if llop.opname == 'malloc_varsize':
-            break
-    assert llop.args[2] is graph.startblock.inputargs[0]
-
-    

pypy/rpython/lltypesystem/rlist.py

         ITEMARRAY = GcArray(ITEM,
                             adtmeths = ADTIFixedList({
                                  "ll_newlist": ll_fixed_newlist,
-                                 "ll_newlist_hint": ll_fixed_newlist,
                                  "ll_newemptylist": ll_fixed_newemptylist,
                                  "ll_length": ll_fixed_length,
                                  "ll_items": ll_fixed_items,
                                               ("items", Ptr(ITEMARRAY)),
                                       adtmeths = ADTIList({
                                           "ll_newlist": ll_newlist,
-                                          "ll_newlist_hint": ll_newlist_hint,
                                           "ll_newemptylist": ll_newemptylist,
                                           "ll_length": ll_length,
                                           "ll_items": ll_items,
 ll_newlist = typeMethod(ll_newlist)
 ll_newlist.oopspec = 'newlist(length)'
 
-def ll_newlist_hint(LIST, lengthhint):
-    ll_assert(lengthhint >= 0, "negative list length")
-    l = malloc(LIST)
-    l.length = 0
-    l.items = malloc(LIST.items.TO, lengthhint)
-    return l
-ll_newlist_hint = typeMethod(ll_newlist_hint)
-ll_newlist_hint.oopspec = 'newlist(length)'
-
 # should empty lists start with no allocated memory, or with a preallocated
 # minimal number of entries?  XXX compare memory usage versus speed, and
 # check how many always-empty lists there are in a typical pypy-c run...
     ll_assert(index < len(l), "fixed setitem out of bounds")
     l[index] = item
 
-def newlist(llops, r_list, items_v, v_sizehint=None):
+def newlist(llops, r_list, items_v):
     LIST = r_list.LIST
     if len(items_v) == 0:
-        if v_sizehint is None:
-            v_result = llops.gendirectcall(LIST.ll_newemptylist)
-        else:
-            v_result = llops.gendirectcall(LIST.ll_newlist_hint, v_sizehint)
+        v_result = llops.gendirectcall(LIST.ll_newemptylist)
     else:
         cno = inputconst(Signed, len(items_v))
         v_result = llops.gendirectcall(LIST.ll_newlist, cno)

pypy/rpython/ootypesystem/rlist.py

     def _make_empty_type(self):
         return ootype.List()
 
-    def _generate_newlist(self, llops, items_v, v_sizehint):
+    def _generate_newlist(self, llops, items_v):
         c_list = inputconst(ootype.Void, self.lowleveltype)
         v_result = llops.genop("new", [c_list], resulttype=self.lowleveltype)
         c_resize = inputconst(ootype.Void, "_ll_resize")
 
 
 
-def newlist(llops, r_list, items_v, v_sizehint=None):
-    # XXX do something about v_sizehint
-    v_result = r_list._generate_newlist(llops, items_v, v_sizehint)
+def newlist(llops, r_list, items_v):
+    v_result = r_list._generate_newlist(llops, items_v)
 
     c_setitem = inputconst(ootype.Void, "ll_setitem_fast")
     for i, v_item in enumerate(items_v):
     def make_iterator_repr(self):
         return ListIteratorRepr(self)
 
-    def _generate_newlist(self, llops, items_v, v_sizehint):
+    def _generate_newlist(self, llops, items_v):
         c_array = inputconst(ootype.Void, self.lowleveltype)
         c_length = inputconst(ootype.Signed, len(items_v))
         v_result = llops.genop("oonewarray", [c_array, c_length], resulttype=self.lowleveltype)

pypy/rpython/rlist.py

         return hop.genop('bool_not', [flag], resulttype=Bool)
 
 
-def rtype_newlist(hop, v_sizehint=None):
+def rtype_newlist(hop):
     nb_args = hop.nb_args
     r_list = hop.r_result
     if r_list == robject.pyobj_repr: # special case: SomeObject lists!
         return v_result
     r_listitem = r_list.item_repr
     items_v = [hop.inputarg(r_listitem, arg=i) for i in range(nb_args)]
-    return hop.rtyper.type_system.rlist.newlist(hop.llops, r_list, items_v,
-                                                v_sizehint=v_sizehint)
+    return hop.rtyper.type_system.rlist.newlist(hop.llops, r_list, items_v)
 
 def rtype_alloc_and_set(hop):
     r_list = hop.r_result

pypy/rpython/test/test_rlist.py

             lis = self.interpret(fnpop, [i])
             assert list_is_clear(lis, 3-i)
 
-    def test_hints(self):
-        from pypy.rlib.objectmodel import newlist
-        from pypy.rpython.annlowlevel import hlstr
-        
-        def f(z):
-            z = hlstr(z)
-            x = newlist(sizehint=13)
-            x += z
-            return ''.join(x)
-
-        res = self.interpret(f, [self.string_to_ll('abc')])
-        assert self.ll_to_string(res) == 'abc'
-
 class TestOOtype(BaseTestRlist, OORtypeMixin):
     rlist = oo_rlist