[pypy-commit] pypy default: Replace this O(n^2) loop with a simple O(n) library function.

alex_gaynor noreply at buildbot.pypy.org
Sun Jul 10 06:13:37 CEST 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r45447:40a63caa7c26
Date: 2011-07-09 21:13 -0700
http://bitbucket.org/pypy/pypy/changeset/40a63caa7c26/

Log:	Replace this O(n^2) loop with a simple O(n) library function.

diff --git a/pypy/module/array/interp_array.py b/pypy/module/array/interp_array.py
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -572,10 +572,7 @@
             self.fromsequence(w_ustr)
 
         def array_tounicode__Array(space, self):
-            u = u""
-            for i in range(self.len):
-                u += self.buffer[i]
-            return space.wrap(u)
+            return space.wrap(rffi.wcharpsize2unicode(self.buffer, self.len))
     else:
 
         def array_fromunicode__Array_Unicode(space, self, w_ustr):


More information about the pypy-commit mailing list