Author: Ronan Lamy <[email protected]>
Branch:
Changeset: r93130:870515a86876
Date: 2017-11-23 06:06 +0000
http://bitbucket.org/pypy/pypy/changeset/870515a86876/
Log: Use a UnicodeBuilder in _io.TextIOWrapper.readline
diff --git a/pypy/module/_io/interp_textio.py b/pypy/module/_io/interp_textio.py
--- a/pypy/module/_io/interp_textio.py
+++ b/pypy/module/_io/interp_textio.py
@@ -646,11 +646,10 @@
self._writeflush(space)
limit = convert_size(space, w_limit)
- chunked = 0
line = None
remaining = None
- chunks = []
+ builder = UnicodeBuilder()
while True:
# First, get some data if necessary
@@ -684,6 +683,7 @@
line_len = len(line)
endpos, consumed = self._find_line_ending(line, start, line_len)
+ chunked = builder.getlength()
if endpos >= 0:
if limit >= 0 and endpos >= start + limit - chunked:
endpos = start + limit - chunked
@@ -702,8 +702,8 @@
# No line ending seen yet - put aside current data
if endpos > start:
s = line[start:endpos]
- chunks.append(s)
- chunked += len(s)
+ builder.append(s)
+
# There may be some remaining bytes we'll have to prepend to the
# next chunk of data
if endpos < line_len:
@@ -719,18 +719,12 @@
self.decoded_chars_used = decoded_chars_used
if start > 0 or endpos < len(line):
line = line[start:endpos]
- if remaining:
- chunks.append(remaining)
- remaining = None
- if chunks:
- if line:
- chunks.append(line)
- line = u''.join(chunks)
+ builder.append(line)
+ elif remaining:
+ builder.append(remaining)
- if line:
- return space.newunicode(line)
- else:
- return space.newunicode(u'')
+ result = builder.build()
+ return space.newunicode(result)
# _____________________________________________________________
# write methods
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit