Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d679e09

Browse files
committed
write(): Special case the common situation of a stream that's only
being used to dump output (no seeks), so we can avoid a lot of extra checks being made.
1 parent c687401 commit d679e09

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

Lib/StringIO.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ def write(self, s):
152152
# Force s to be a string or unicode
153153
if not isinstance(s, basestring):
154154
s = str(s)
155+
if self.pos == self.len:
156+
self.buflist.append(s)
157+
self.len = self.pos = self.pos + len(s)
158+
return
155159
if self.pos > self.len:
156160
self.buflist.append('\0'*(self.pos - self.len))
157161
self.len = self.pos

0 commit comments

Comments
 (0)