[pypy-commit] pypy default: Fix comment, and simplify the final logic.
arigo
noreply at buildbot.pypy.org
Mon Dec 26 17:11:07 CET 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r50879:f9932c00e2d2
Date: 2011-12-26 17:07 +0100
http://bitbucket.org/pypy/pypy/changeset/f9932c00e2d2/
Log: Fix comment, and simplify the final logic.
diff --git a/pypy/objspace/std/stringobject.py b/pypy/objspace/std/stringobject.py
--- a/pypy/objspace/std/stringobject.py
+++ b/pypy/objspace/std/stringobject.py
@@ -537,7 +537,7 @@
builder.append(by)
builder.append_slice(input, upper, len(input))
else:
- # An ok guess for the result size
+ # First compute the exact result size
count = input.count(sub)
if count > maxsplit and maxsplit > 0:
count = maxsplit
@@ -553,21 +553,16 @@
builder = StringBuilder(result_size)
start = 0
sublen = len(sub)
- first = True
while maxsplit != 0:
next = input.find(sub, start)
if next < 0:
break
- if not first:
- builder.append(by)
- first = False
builder.append_slice(input, start, next)
+ builder.append(by)
start = next + sublen
maxsplit -= 1 # NB. if it's already < 0, it stays < 0
- if not first:
- builder.append(by)
builder.append_slice(input, start, len(input))
return space.wrap(builder.build())
More information about the pypy-commit
mailing list