summaryrefslogtreecommitdiffstats
path: root/Lib/StringIO.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-09-23 06:43:25 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-09-23 06:43:25 (GMT)
commit0336e1fe8cd1fc7c7d6d710261305111fbbe1d52 (patch)
treeb8cc4b94fbccea85dac8407b2c22672b4f357eb7 /Lib/StringIO.py
parent7ec642a4d2ee98dfc0b67431255046374abc4ed7 (diff)
downloadcpython-0336e1fe8cd1fc7c7d6d710261305111fbbe1d52.zip
cpython-0336e1fe8cd1fc7c7d6d710261305111fbbe1d52.tar.gz
cpython-0336e1fe8cd1fc7c7d6d710261305111fbbe1d52.tar.bz2
Use local variables in StringIO.write().
Makes it easier on the eyes and a bit more snappy.
Diffstat (limited to 'Lib/StringIO.py')
-rw-r--r--Lib/StringIO.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/Lib/StringIO.py b/Lib/StringIO.py
index 1b9fa7b..a43e5d4 100644
--- a/Lib/StringIO.py
+++ b/Lib/StringIO.py
@@ -215,21 +215,22 @@ class StringIO:
# Force s to be a string or unicode
if not isinstance(s, basestring):
s = str(s)
- if self.pos == self.len:
+ spos = self.pos
+ slen = self.len
+ if spos == slen:
self.buflist.append(s)
- self.len = self.pos = self.pos + len(s)
+ self.len = self.pos = slen = spos = spos + len(s)
return
- if self.pos > self.len:
- self.buflist.append('\0'*(self.pos - self.len))
- self.len = self.pos
- newpos = self.pos + len(s)
- if self.pos < self.len:
+ if spos > slen:
+ self.buflist.append('\0'*(spos - slen))
+ slen = spos
+ newpos = spos + len(s)
+ if spos < slen:
if self.buflist:
self.buf += ''.join(self.buflist)
- self.buflist = []
- self.buflist = [self.buf[:self.pos], s, self.buf[newpos:]]
+ self.buflist = [self.buf[:spos], s, self.buf[newpos:]]
self.buf = ''
- if newpos > self.len:
+ if newpos > slen:
self.len = newpos
else:
self.buflist.append(s)