[pypy-commit] pypy speedup-list-comprehension: store sizehint on listobjects
fijal
noreply at buildbot.pypy.org
Thu Feb 23 16:37:49 CET 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: speedup-list-comprehension
Changeset: r52809:a3b63091cb8c
Date: 2012-02-23 08:37 -0700
http://bitbucket.org/pypy/pypy/changeset/a3b63091cb8c/
Log: store sizehint on listobjects
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -721,7 +721,7 @@
lgt = self.space.int_w(self.space.len(last_val))
except OperationError:
lgt = 0 # oh well
- self.pushvalue(self.space.newlist(newlist(lgt)))
+ self.pushvalue(self.space.newlist([], sizehint=lgt))
self.pushvalue(last_val)
def LOAD_ATTR(self, nameindex, next_instr):
diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -7,7 +7,7 @@
from pypy.objspace.std.sliceobject import W_SliceObject, normalize_simple_slice
from pypy.objspace.std import slicetype
from pypy.interpreter import gateway, baseobjspace
-from pypy.rlib.objectmodel import instantiate, specialize
+from pypy.rlib.objectmodel import instantiate, specialize, newlist
from pypy.rlib.listsort import make_timsort_class
from pypy.rlib import rerased, jit, debug
from pypy.interpreter.argument import Signature
@@ -75,13 +75,15 @@
class W_ListObject(W_AbstractListObject):
from pypy.objspace.std.listtype import list_typedef as typedef
- def __init__(w_self, space, wrappeditems):
+ def __init__(w_self, space, wrappeditems, sizehint=-1):
assert isinstance(wrappeditems, list)
w_self.space = space
if space.config.objspace.std.withliststrategies:
- w_self.strategy = get_strategy_from_list_objects(space, wrappeditems)
+ w_self.strategy = get_strategy_from_list_objects(space,
+ wrappeditems)
else:
w_self.strategy = space.fromcache(ObjectListStrategy)
+ w_self.sizehint = sizehint
w_self.init_from_list_w(wrappeditems)
@staticmethod
@@ -397,7 +399,7 @@
else:
strategy = self.space.fromcache(ObjectListStrategy)
- storage = strategy.get_empty_storage()
+ storage = strategy.get_empty_storage(w_list.sizehint)
w_list.strategy = strategy
w_list.lstorage = storage
@@ -660,8 +662,8 @@
l = [self.unwrap(w_item) for w_item in list_w]
w_list.lstorage = self.erase(l)
- def get_empty_storage(self):
- return self.erase([])
+ def get_empty_storage(self, sizehint):
+ return self.erase(newlist(sizehint))
def clone(self, w_list):
l = self.unerase(w_list.lstorage)
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -300,8 +300,9 @@
make_sure_not_resized(list_w)
return wraptuple(self, list_w)
- def newlist(self, list_w):
- return W_ListObject(self, list_w)
+ def newlist(self, list_w, sizehint=-1):
+ assert not list_w or sizehint == -1
+ return W_ListObject(self, list_w, sizehint)
def newlist_str(self, list_s):
return W_ListObject.newlist_str(self, list_s)
More information about the pypy-commit
mailing list