1. Pypy
  2. Untitled project
  3. pypy

Commits

Brian Kearns  committed 2924a59

(fijal, agaynor) another try at presizing

  • Participants
  • Parent commits f5a9767
  • Branches default

Comments (0)

Files changed (1)

File rpython/rlib/rstring.py

View file
  • Ignore whitespace
 
 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
     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)
     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: