[pypy-svn] r70965 - pypy/trunk/pypy/rlib

arigo at codespeak.net arigo at codespeak.net
Fri Jan 29 13:01:23 CET 2010


Author: arigo
Date: Fri Jan 29 13:01:23 2010
New Revision: 70965

Modified:
   pypy/trunk/pypy/rlib/rstring.py
Log:
Forgot to check this in.


Modified: pypy/trunk/pypy/rlib/rstring.py
==============================================================================
--- pypy/trunk/pypy/rlib/rstring.py	(original)
+++ pypy/trunk/pypy/rlib/rstring.py	Fri Jan 29 13:01:23 2010
@@ -31,6 +31,26 @@
     def build(self):
         return u''.join(self.l)
 
+
+def string_repeat(s, mul):
+    """Repeat a string or unicode.  Note that this assumes that 'mul' > 0."""
+    result = None
+    factor = 1
+    assert mul > 0
+    limit = mul >> 1
+    while True:
+        if mul & factor:
+            if result is None:
+                result = s
+            else:
+                result = s + result
+            if factor > limit:
+                break
+        s += s
+        factor *= 2
+    return result
+string_repeat._annspecialcase_ = 'specialize:argtype(0)'
+
 # ------------------------------------------------------------
 # ----------------- implementation details -------------------
 # ------------------------------------------------------------



More information about the Pypy-commit mailing list