Author: Philip Jenvey <[email protected]>
Branch:
Changeset: r60433:8f5beaa9c51a
Date: 2013-01-24 16:27 -0800
http://bitbucket.org/pypy/pypy/changeset/8f5beaa9c51a/
Log: preallocate the bytearraydata via length_hint
diff --git a/pypy/objspace/std/bytearraytype.py
b/pypy/objspace/std/bytearraytype.py
--- a/pypy/objspace/std/bytearraytype.py
+++ b/pypy/objspace/std/bytearraytype.py
@@ -15,6 +15,7 @@
str_splitlines, str_translate)
from pypy.objspace.std.listtype import (
list_append, list_extend)
+from rpython.rlib.objectmodel import newlist_hint, resizelist_hint
bytearray_insert = SMM('insert', 3,
@@ -87,8 +88,10 @@
return [c for c in string]
# sequence of bytes
- data = []
w_iter = space.iter(w_source)
+ length_hint = space.length_hint(w_source, 0)
+ data = newlist_hint(length_hint)
+ extended = 0
while True:
try:
w_item = space.next(w_iter)
@@ -98,6 +101,9 @@
break
value = getbytevalue(space, w_item)
data.append(value)
+ extended += 1
+ if extended < length_hint:
+ resizelist_hint(data, extended)
return data
def descr_bytearray__reduce__(space, w_self):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit