[pypy-commit] pypy default: Preallocate the result for str.__repr__ more appropriately, use len(self) + 2, which will be correct in the common case of "no special characgters".

alex_gaynor noreply at buildbot.pypy.org
Fri Jul 29 00:39:26 CEST 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r46073:7982de091965
Date: 2011-07-28 15:39 -0700
http://bitbucket.org/pypy/pypy/changeset/7982de091965/

Log:	Preallocate the result for str.__repr__ more appropriately, use
	len(self) + 2, which will be correct in the common case of "no
	special characgters".

	Alex

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
@@ -913,7 +913,7 @@
 def repr__String(space, w_str):
     s = w_str._value
 
-    buf = StringBuilder(50)
+    buf = StringBuilder(len(s) + 2)
 
     quote = "'"
     if quote in s and '"' not in s:


More information about the pypy-commit mailing list