Revision: 4f22a0ff95a4
Author:   Mikko Korpela <[email protected]>
Date:     Fri Jun 10 13:50:23 2011
Log: jsparser: Replace StringIO with list -- based on profiling measurements
http://code.google.com/p/robotframework/source/detail?r=4f22a0ff95a4

Modified:
 /src/robot/serializing/jsparser.py

=======================================
--- /src/robot/serializing/jsparser.py  Fri Jun 10 05:02:35 2011
+++ /src/robot/serializing/jsparser.py  Fri Jun 10 13:50:23 2011
@@ -13,7 +13,6 @@
 #  limitations under the License.

 from __future__ import with_statement
-import StringIO
 import xml.sax as sax
 from xml.sax.handler import ContentHandler
 import zlib
@@ -435,15 +434,15 @@

     def startElement(self, name, attrs):
         handler = self._handler_stack[-1].get_handler_for(name, attrs)
-        self._charbuffer = StringIO.StringIO()
+        self._charbuffer = []
         self._handler_stack.append(handler)

     def endElement(self, name):
         handler = self._handler_stack.pop()
- self._handler_stack[-1].add_child(handler.end_element(self._charbuffer.getvalue())) + self._handler_stack[-1].add_child(handler.end_element(''.join(self._charbuffer)))

     def characters(self, content):
-        self._charbuffer.write(content)
+        self._charbuffer += [content]


 class DataModel(object):
@@ -502,10 +501,10 @@
     string = string.replace('\n', '\\n')
     string = string.replace('\r', '\\r')
     string = string.replace('\t', '\\t')
-    result = StringIO.StringIO()
+    result = []
     for c in string:
-        result.write(get_matching_char(c))
-    return '"'+result.getvalue()+'"'
+        result += [get_matching_char(c)]
+    return '"'+''.join(result)+'"'

 def json_dump(data, output):
     if data is None:

Reply via email to