Author: Alex Gaynor <[email protected]>
Branch:
Changeset: r47941:c154a210d625
Date: 2011-10-11 12:33 -0400
http://bitbucket.org/pypy/pypy/changeset/c154a210d625/
Log: make str.captitalize not do extra copies.
diff --git a/pypy/objspace/std/stringobject.py
b/pypy/objspace/std/stringobject.py
--- a/pypy/objspace/std/stringobject.py
+++ b/pypy/objspace/std/stringobject.py
@@ -178,24 +178,24 @@
def str_capitalize__String(space, w_self):
input = w_self._value
- buffer = [' '] * len(input)
+ builder = StringBuilder(len(input))
if len(input) > 0:
ch = input[0]
if ch.islower():
o = ord(ch) - 32
- buffer[0] = chr(o)
+ builder.append(chr(o))
else:
- buffer[0] = ch
+ builder.append(ch)
for i in range(1, len(input)):
ch = input[i]
if ch.isupper():
o = ord(ch) + 32
- buffer[i] = chr(o)
+ builder.append(chr(o))
else:
- buffer[i] = ch
+ builder.append(ch)
- return space.wrap("".join(buffer))
+ return space.wrap(builder.build())
def str_title__String(space, w_self):
input = w_self._value
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit