[pypy-svn] r43285 - pypy/branch/pypy-string-formatting/objspace/std

arigo at codespeak.net arigo at codespeak.net
Sat May 12 13:54:21 CEST 2007


Author: arigo
Date: Sat May 12 13:54:20 2007
New Revision: 43285

Modified:
   pypy/branch/pypy-string-formatting/objspace/std/formatting.py
Log:
Use the newly supported efficient "lst += string" constructions.


Modified: pypy/branch/pypy-string-formatting/objspace/std/formatting.py
==============================================================================
--- pypy/branch/pypy-string-formatting/objspace/std/formatting.py	(original)
+++ pypy/branch/pypy-string-formatting/objspace/std/formatting.py	Sat May 12 13:54:20 2007
@@ -39,6 +39,7 @@
 
     def std_wp_int(self, r, prefix=''):
         # use self.prec to add some '0' on the left of the number
+        import pdb; pdb.set_trace()
         if self.prec >= 0:
             sign = r[0] == '-'
             padding = self.prec - (len(r)-int(sign))
@@ -248,14 +249,15 @@
             while True:
                 # fast path: consume as many characters as possible
                 fmt = self.fmt
-                i = self.fmtpos
+                i = i0 = self.fmtpos
                 while i < len(fmt):
                     if fmt[i] == '%':
                         break
-                    result.append(fmt[i])
                     i += 1
                 else:
+                    result += fmt[i0:]
                     break     # end of 'fmt' string 
+                result += fmt[i0:i]
                 self.fmtpos = i + 1
 
                 # interpret the next formatter
@@ -308,13 +310,10 @@
             result = self.result
             padding = self.width - length
             if not self.f_ljust:
-                for i in range(padding):   # add any padding at the left of 'r'
-                    result.append(' ')
+                result += ' ' * padding    # add any padding at the left of 'r'
                 padding = 0
-            for i in range(length):    # add 'r' itself
-                result.append(r[i])
-            for i in range(padding):   # add any remaining padding at the right
-                result.append(' ')
+            result += r[:length]       # add 'r' itself
+            result += ' ' * padding    # add any remaining padding at the right
         std_wp._annspecialcase_ = 'specialize:argtype(1)'
 
         def std_wp_number(self, r, prefix=''):
@@ -341,20 +340,15 @@
                 padnumber = '>'
 
             if padnumber == '>':
-                for i in range(padding):
-                    result.append(' ')     # pad with spaces on the left
+                result += ' ' * padding    # pad with spaces on the left
             if sign:
                 result.append(r[0])        # the sign
-            for c in prefix:
-                result.append(c)           # the prefix
+            result += prefix               # the prefix
             if padnumber == '0':
-                for i in range(padding):   # pad with zeroes
-                    result.append('0')
-            for j in range(int(sign), len(r)):   # the rest of the number
-                result.append(r[j])
+                result += '0' * padding    # pad with zeroes
+            result += r[int(sign):]        # the rest of the number
             if padnumber == '<':           # spaces on the right
-                for i in range(padding):
-                    result.append(' ')
+                result += ' ' * padding
 
         def fmt_s(self, w_value):
             space = self.space


More information about the pypy-svn mailing list