[pypy-commit] pypy default: A bit experimental - try to preallocate the size of unicode join and remove
fijal
noreply at buildbot.pypy.org
Mon Jan 16 21:16:09 CET 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch:
Changeset: r51364:f6b8525d8a10
Date: 2012-01-16 22:14 +0200
http://bitbucket.org/pypy/pypy/changeset/f6b8525d8a10/
Log: A bit experimental - try to preallocate the size of unicode join and
remove a pointless performance hack (the general optimization should
work already)
diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -201,7 +201,7 @@
return space.newbool(container.find(item) != -1)
def unicode_join__Unicode_ANY(space, w_self, w_list):
- list_w = space.unpackiterable(w_list)
+ list_w = space.listview(w_list)
size = len(list_w)
if size == 0:
@@ -216,22 +216,21 @@
def _unicode_join_many_items(space, w_self, list_w, size):
self = w_self._value
- sb = UnicodeBuilder()
+ prealloc_size = 0
+ for i in range(size):
+ prealloc_size += len(space.unicode_w(list_w[i]))
+ sb = UnicodeBuilder(prealloc_size)
for i in range(size):
if self and i != 0:
sb.append(self)
w_s = list_w[i]
- if isinstance(w_s, W_UnicodeObject):
- # shortcut for performance
- sb.append(w_s._value)
- else:
- try:
- sb.append(space.unicode_w(w_s))
- except OperationError, e:
- if not e.match(space, space.w_TypeError):
- raise
- raise operationerrfmt(space.w_TypeError,
- "sequence item %d: expected string or Unicode", i)
+ try:
+ sb.append(space.unicode_w(w_s))
+ except OperationError, e:
+ if not e.match(space, space.w_TypeError):
+ raise
+ raise operationerrfmt(space.w_TypeError,
+ "sequence item %d: expected string or Unicode", i)
return space.wrap(sb.build())
def hash__Unicode(space, w_uni):
More information about the pypy-commit
mailing list