[Checkins] SVN: zope.tal/trunk/ Updated `talinterpreter.FasterStringIO` to faster list-based implementation.
Hanno Schlichting
hannosch at hannosch.eu
Sat Aug 20 12:02:17 EDT 2011
Log message for revision 122628:
Updated `talinterpreter.FasterStringIO` to faster list-based implementation.
Changed:
U zope.tal/trunk/CHANGES.txt
U zope.tal/trunk/src/zope/tal/talinterpreter.py
-=-
Modified: zope.tal/trunk/CHANGES.txt
===================================================================
--- zope.tal/trunk/CHANGES.txt 2011-08-20 15:58:20 UTC (rev 122627)
+++ zope.tal/trunk/CHANGES.txt 2011-08-20 16:02:17 UTC (rev 122628)
@@ -5,6 +5,8 @@
3.6.0 (unreleased)
------------------
+- Updated `talinterpreter.FasterStringIO` to faster list-based implementation.
+
- Increase the default value of the `wrap` argument from 60 to 1023 characters,
to avoid extra whitespace and line breaks.
Modified: zope.tal/trunk/src/zope/tal/talinterpreter.py
===================================================================
--- zope.tal/trunk/src/zope/tal/talinterpreter.py 2011-08-20 15:58:20 UTC (rev 122627)
+++ zope.tal/trunk/src/zope/tal/talinterpreter.py 2011-08-20 16:02:17 UTC (rev 122628)
@@ -18,9 +18,6 @@
import sys
import warnings
-# Do not use cStringIO here! It's not unicode aware. :(
-from StringIO import StringIO
-
from zope.i18nmessageid import Message
from zope.tal.taldefs import quote, TAL_VERSION, METALError
from zope.tal.taldefs import isCurrentVersion
@@ -996,23 +993,18 @@
bytecode_handlers_tal["optTag"] = do_optTag_tal
-class FasterStringIO(StringIO):
- """Append-only version of StringIO.
-
- This let's us have a much faster write() method.
+class FasterStringIO(list):
+ """Unicode-aware append-only version of StringIO.
"""
- def close(self):
- if not self.closed:
- self.write = _write_ValueError
- StringIO.close(self)
+ write = list.append
- def seek(self, pos, mode=0):
- raise RuntimeError("FasterStringIO.seek() not allowed")
+ def __init__(self, value=None):
+ list.__init__(self)
+ if value is not None:
+ self.append(value)
- def write(self, s):
- #assert self.pos == self.len
- self.buflist.append(s)
- self.len = self.pos = self.pos + len(s)
+ def getvalue(self):
+ return u''.join(self)
def _write_ValueError(s):
More information about the checkins
mailing list