summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-04-12 05:24:24 (GMT)
committerGuido van Rossum <guido@python.org>2007-04-12 05:24:24 (GMT)
commitaa43ed95cd14366e95a724cb94eb9369195fb27b (patch)
treec7c9c0a3f1a7469e636fca784910db918b37b147
parent57b39e0916d741d9851ac875d8f443bfc6005def (diff)
downloadcpython-aa43ed95cd14366e95a724cb94eb9369195fb27b.zip
cpython-aa43ed95cd14366e95a724cb94eb9369195fb27b.tar.gz
cpython-aa43ed95cd14366e95a724cb94eb9369195fb27b.tar.bz2
TextIO improvement:
- 25% speed increse in tell(); - f.seek(0, 1) now maps to f.seek(f.tell(), 0) instead of to f.tell().
-rw-r--r--Lib/io.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/Lib/io.py b/Lib/io.py
index 21f72c8..ccdb3fb 100644
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -992,8 +992,9 @@ class TextIOWrapper(TextIOBase):
return self._encode_decoder_state(decoder_state, position)
decoder = pickle.loads(decoder_state)
n = 0
- for i, b in enumerate(readahead):
- n += len(decoder.decode(bytes([b])))
+ bb = bytes(1)
+ for i, bb[0] in enumerate(readahead):
+ n += len(decoder.decode(bb))
if n >= needed:
decoder_state = pickle.dumps(decoder, 2)
return self._encode_decoder_state(decoder_state, position+i+1)
@@ -1005,7 +1006,8 @@ class TextIOWrapper(TextIOBase):
if whence == 1:
if pos != 0:
raise IOError("Can't do nonzero cur-relative seeks")
- return self.tell()
+ pos = self.tell()
+ whence = 0
if whence == 2:
if pos != 0:
raise IOError("Can't do nonzero end-relative seeks")