Commit 08ce728f authored by Stefan Behnel's avatar Stefan Behnel

Compile the Cython.StringIOTree module by default to speed up the code generation a little.

parent ad3fef8e
cimport cython
cdef object StringIO
@cython.final
cdef class StringIOTree:
cdef public list prepended_children
cdef public object stream
......@@ -8,6 +11,8 @@ cdef class StringIOTree:
@cython.locals(x=StringIOTree)
cpdef getvalue(self)
@cython.locals(x=StringIOTree)
cdef _collect_in(self, list target_list)
@cython.locals(child=StringIOTree)
cpdef copyto(self, target)
cpdef commit(self)
......
......@@ -39,7 +39,6 @@ try:
from cStringIO import StringIO
except ImportError:
from io import StringIO
import sys
class StringIOTree(object):
......@@ -56,10 +55,17 @@ class StringIOTree(object):
self.markers = []
def getvalue(self):
content = [x.getvalue() for x in self.prepended_children]
content.append(self.stream.getvalue())
content = []
self._collect_in(content)
return "".join(content)
def _collect_in(self, target_list):
for x in self.prepended_children:
x._collect_in(target_list)
stream_content = self.stream.getvalue()
if stream_content:
target_list.append(stream_content)
def copyto(self, target):
"""Potentially cheaper than getvalue as no string concatenation
needs to happen."""
......@@ -108,6 +114,7 @@ class StringIOTree(object):
children = self.prepended_children
return [m for c in children for m in c.allmarkers()] + self.markers
"""
# Print the result of allmarkers in a nice human-readable form. Use it only for debugging.
# Prints e.g.
# /path/to/source.pyx:
......@@ -147,4 +154,7 @@ class StringIOTree(object):
reprstr += "-" + str(c_linenos[i]) + " "
i += 1
reprstr += "\n"
import sys
sys.stdout.write(reprstr)
"""
......@@ -93,10 +93,10 @@ def compile_cython_modules(profile=False, coverage=False, compile_more=False, cy
"Cython.Runtime.refnanny",
"Cython.Compiler.FusedNode",
"Cython.Tempita._tempita",
"Cython.StringIOTree",
]
if compile_more:
compiled_modules.extend([
"Cython.StringIOTree",
"Cython.Compiler.Code",
"Cython.Compiler.Lexicon",
"Cython.Compiler.Parsing",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment