]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
write(): Special case the common situation of a stream that's only
authorFred Drake <fdrake@acm.org>
Tue, 17 Sep 2002 18:10:34 +0000 (18:10 +0000)
committerFred Drake <fdrake@acm.org>
Tue, 17 Sep 2002 18:10:34 +0000 (18:10 +0000)
          being used to dump output (no seeks), so we can avoid a lot
          of extra checks being made.

Lib/StringIO.py

index 7c4b6c7705c71583600b22616ea20174f53f178a..79ab7e16b3291c35da4f4cecffa9c6b03fa542da 100644 (file)
@@ -152,6 +152,10 @@ class StringIO:
         # Force s to be a string or unicode
         if not isinstance(s, basestring):
             s = str(s)
+        if self.pos == self.len:
+            self.buflist.append(s)
+            self.len = self.pos = self.pos + len(s)
+            return
         if self.pos > self.len:
             self.buflist.append('\0'*(self.pos - self.len))
             self.len = self.pos