[pypy-commit] pypy default: (fijal, agaynor) another try at presizing

bdkearns noreply at buildbot.pypy.org
Tue Feb 12 22:55:27 CET 2013


Author: Brian Kearns <bdkearns at gmail.com>
Branch: 
Changeset: r61151:2924a59b74ba
Date: 2013-02-12 16:54 -0500
http://bitbucket.org/pypy/pypy/changeset/2924a59b74ba/

Log:	(fijal, agaynor) another try at presizing

diff --git a/rpython/rlib/rstring.py b/rpython/rlib/rstring.py
--- a/rpython/rlib/rstring.py
+++ b/rpython/rlib/rstring.py
@@ -3,6 +3,7 @@
 
 from rpython.annotator.model import (SomeObject, SomeString, s_None, SomeChar,
     SomeInteger, SomeUnicodeCodePoint, SomeUnicodeString, SomePtr, SomePBC)
+from rpython.rlib.objectmodel import newlist_hint
 from rpython.rlib.rarithmetic import ovfcheck
 from rpython.rtyper.extregistry import ExtRegistryEntry
 from rpython.tool.pairtype import pairtype
@@ -14,7 +15,10 @@
     if bylen == 0:
         raise ValueError("empty separator")
 
-    res = []
+    if maxsplit > 0:
+        res = newlist_hint(min(maxsplit, len(value)))
+    else:
+        res = []
     start = 0
     while maxsplit != 0:
         next = value.find(by, start)
@@ -27,8 +31,12 @@
     res.append(value[start:len(value)])
     return res
 
+
 def rsplit(value, by, maxsplit=-1):
-    res = []
+    if maxsplit > 0:
+        res = newlist_hint(min(maxsplit, len(value)))
+    else:
+        res = []
     end = len(value)
     bylen = len(by)
     if bylen == 0:


More information about the pypy-commit mailing list