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 cimport cython
cdef object StringIO
@cython.final
cdef class StringIOTree: cdef class StringIOTree:
cdef public list prepended_children cdef public list prepended_children
cdef public object stream cdef public object stream
...@@ -8,6 +11,8 @@ cdef class StringIOTree: ...@@ -8,6 +11,8 @@ cdef class StringIOTree:
@cython.locals(x=StringIOTree) @cython.locals(x=StringIOTree)
cpdef getvalue(self) cpdef getvalue(self)
@cython.locals(x=StringIOTree)
cdef _collect_in(self, list target_list)
@cython.locals(child=StringIOTree) @cython.locals(child=StringIOTree)
cpdef copyto(self, target) cpdef copyto(self, target)
cpdef commit(self) cpdef commit(self)
......
...@@ -39,7 +39,6 @@ try: ...@@ -39,7 +39,6 @@ try:
from cStringIO import StringIO from cStringIO import StringIO
except ImportError: except ImportError:
from io import StringIO from io import StringIO
import sys
class StringIOTree(object): class StringIOTree(object):
...@@ -56,10 +55,17 @@ class StringIOTree(object): ...@@ -56,10 +55,17 @@ class StringIOTree(object):
self.markers = [] self.markers = []
def getvalue(self): def getvalue(self):
content = [x.getvalue() for x in self.prepended_children] content = []
content.append(self.stream.getvalue()) self._collect_in(content)
return "".join(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): def copyto(self, target):
"""Potentially cheaper than getvalue as no string concatenation """Potentially cheaper than getvalue as no string concatenation
needs to happen.""" needs to happen."""
...@@ -108,6 +114,7 @@ class StringIOTree(object): ...@@ -108,6 +114,7 @@ class StringIOTree(object):
children = self.prepended_children children = self.prepended_children
return [m for c in children for m in c.allmarkers()] + self.markers 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. # Print the result of allmarkers in a nice human-readable form. Use it only for debugging.
# Prints e.g. # Prints e.g.
# /path/to/source.pyx: # /path/to/source.pyx:
...@@ -147,4 +154,7 @@ class StringIOTree(object): ...@@ -147,4 +154,7 @@ class StringIOTree(object):
reprstr += "-" + str(c_linenos[i]) + " " reprstr += "-" + str(c_linenos[i]) + " "
i += 1 i += 1
reprstr += "\n" reprstr += "\n"
import sys
sys.stdout.write(reprstr) sys.stdout.write(reprstr)
"""
...@@ -93,10 +93,10 @@ def compile_cython_modules(profile=False, coverage=False, compile_more=False, cy ...@@ -93,10 +93,10 @@ def compile_cython_modules(profile=False, coverage=False, compile_more=False, cy
"Cython.Runtime.refnanny", "Cython.Runtime.refnanny",
"Cython.Compiler.FusedNode", "Cython.Compiler.FusedNode",
"Cython.Tempita._tempita", "Cython.Tempita._tempita",
"Cython.StringIOTree",
] ]
if compile_more: if compile_more:
compiled_modules.extend([ compiled_modules.extend([
"Cython.StringIOTree",
"Cython.Compiler.Code", "Cython.Compiler.Code",
"Cython.Compiler.Lexicon", "Cython.Compiler.Lexicon",
"Cython.Compiler.Parsing", "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