Author: Alex Gaynor <[email protected]>
Branch:
Changeset: r61116:ee04c61f776b
Date: 2013-02-11 22:05 -0800
http://bitbucket.org/pypy/pypy/changeset/ee04c61f776b/
Log: attempt to presize tehse lists
diff --git a/rpython/rlib/rstring.py b/rpython/rlib/rstring.py
--- a/rpython/rlib/rstring.py
+++ b/rpython/rlib/rstring.py
@@ -3,9 +3,10 @@
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.tool.pairtype import pair, pairtype
from rpython.rtyper.extregistry import ExtRegistryEntry
+from rpython.tool.pairtype import pairtype
# -------------- public API for string functions -----------------------
@@ -14,7 +15,10 @@
if bylen == 0:
raise ValueError("empty separator")
- res = []
+ if maxsplit > 0:
+ res = newlist_hint(maxsplit)
+ 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(maxsplit)
+ else:
+ res = []
end = len(value)
bylen = len(by)
if bylen == 0:
@@ -38,7 +46,7 @@
next = value.rfind(by, 0, end)
if next < 0:
break
- res.append(value[next+bylen:end])
+ res.append(value[next + bylen:end])
end = next
maxsplit -= 1 # NB. if it's already < 0, it stays < 0
@@ -50,6 +58,7 @@
INIT_SIZE = 100 # XXX tweak
+
class AbstractStringBuilder(object):
def __init__(self, init_size=INIT_SIZE):
self.l = []
@@ -91,9 +100,11 @@
def getlength(self):
return len(self.build())
+
class StringBuilder(AbstractStringBuilder):
tp = str
+
class UnicodeBuilder(AbstractStringBuilder):
tp = unicode
@@ -260,4 +271,3 @@
def specialize_call(self, hop):
hop.exception_cannot_occur()
-
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit