Commit 860d2932 authored by Stefan Behnel's avatar Stefan Behnel

minor speed-ups in code writer

parent 7f9324d5
...@@ -33,10 +33,11 @@ class CCodeWriter: ...@@ -33,10 +33,11 @@ class CCodeWriter:
def __init__(self, f): def __init__(self, f):
#self.f = open_new_file(outfile_name) #self.f = open_new_file(outfile_name)
self.f = f self.f = f
self._write = f.write
self.level = 0 self.level = 0
self.bol = 1 self.bol = 1
self.marker = None self.marker = None
self.last_marker = 1 self.last_marker_line = 0
self.label_counter = 1 self.label_counter = 1
self.error_label = None self.error_label = None
self.filename_table = {} self.filename_table = {}
...@@ -49,14 +50,14 @@ class CCodeWriter: ...@@ -49,14 +50,14 @@ class CCodeWriter:
self.emit_marker() self.emit_marker()
if code: if code:
self.put(code) self.put(code)
self.f.write("\n"); self._write("\n");
self.bol = 1 self.bol = 1
def emit_marker(self): def emit_marker(self):
self.f.write("\n"); self._write("\n");
self.indent() self.indent()
self.f.write("/* %s */\n" % self.marker) self._write("/* %s */\n" % self.marker[1])
self.last_marker = self.marker self.last_marker_line = self.marker[0]
self.marker = None self.marker = None
def put(self, code): def put(self, code):
...@@ -65,7 +66,7 @@ class CCodeWriter: ...@@ -65,7 +66,7 @@ class CCodeWriter:
self.level += dl self.level += dl
if self.bol: if self.bol:
self.indent() self.indent()
self.f.write(code) self._write(code)
self.bol = 0 self.bol = 0
if dl > 0: if dl > 0:
self.level += dl self.level += dl
...@@ -85,7 +86,7 @@ class CCodeWriter: ...@@ -85,7 +86,7 @@ class CCodeWriter:
self.putln("}") self.putln("}")
def indent(self): def indent(self):
self.f.write(" " * self.level) self._write(" " * self.level)
def get_py_version_hex(self, pyversion): def get_py_version_hex(self, pyversion):
return "0x%02X%02X%02X%02X" % (tuple(pyversion) + (0,0,0,0))[:4] return "0x%02X%02X%02X%02X" % (tuple(pyversion) + (0,0,0,0))[:4]
...@@ -105,6 +106,8 @@ class CCodeWriter: ...@@ -105,6 +106,8 @@ class CCodeWriter:
if pos is None: if pos is None:
return return
source_desc, line, col = pos source_desc, line, col = pos
if self.last_marker_line == line:
return
assert isinstance(source_desc, SourceDescriptor) assert isinstance(source_desc, SourceDescriptor)
contents = self.commented_file_contents(source_desc) contents = self.commented_file_contents(source_desc)
...@@ -114,8 +117,7 @@ class CCodeWriter: ...@@ -114,8 +117,7 @@ class CCodeWriter:
marker = u'"%s":%d\n%s\n' % ( marker = u'"%s":%d\n%s\n' % (
source_desc.get_escaped_description(), line, u'\n'.join(lines)) source_desc.get_escaped_description(), line, u'\n'.join(lines))
if self.last_marker != marker: self.marker = (line, marker)
self.marker = marker
def init_labels(self): def init_labels(self):
self.label_counter = 0 self.label_counter = 0
......
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