Commit 8098e6a0 authored by Stefan Behnel's avatar Stefan Behnel

Reduce the processing overhead in the debug line mapping writer a little.

parent 04edac6e
...@@ -9,13 +9,14 @@ cython.declare(Naming=object, Options=object, PyrexTypes=object, TypeSlots=objec ...@@ -9,13 +9,14 @@ cython.declare(Naming=object, Options=object, PyrexTypes=object, TypeSlots=objec
error=object, warning=object, py_object_type=object, UtilityCode=object, error=object, warning=object, py_object_type=object, UtilityCode=object,
EncodedString=object, re=object) EncodedString=object, re=object)
from collections import defaultdict
import json import json
import operator
import os import os
import re import re
import operator
from .PyrexTypes import CPtrType from .PyrexTypes import CPtrType
from . import Future from . import Future
from . import Annotate from . import Annotate
from . import Code from . import Code
from . import Naming from . import Naming
...@@ -456,19 +457,18 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -456,19 +457,18 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
tb = env.context.gdb_debug_outputwriter tb = env.context.gdb_debug_outputwriter
markers = ccodewriter.buffer.allmarkers() markers = ccodewriter.buffer.allmarkers()
d = {} d = defaultdict(list)
for c_lineno, cython_lineno in enumerate(markers): for c_lineno, cython_lineno in enumerate(markers):
if cython_lineno > 0: if cython_lineno > 0:
d.setdefault(cython_lineno, []).append(c_lineno + 1) d[cython_lineno].append(c_lineno + 1)
tb.start('LineNumberMapping') tb.start('LineNumberMapping')
for cython_lineno, c_linenos in sorted(d.items()): for cython_lineno, c_linenos in sorted(d.items()):
attrs = { tb.add_entry(
'c_linenos': ' '.join(map(str, c_linenos)), 'LineNumber',
'cython_lineno': str(cython_lineno), c_linenos=' '.join(map(str, c_linenos)),
} cython_lineno=str(cython_lineno),
tb.start('LineNumber', attrs) )
tb.end('LineNumber')
tb.end('LineNumberMapping') tb.end('LineNumberMapping')
tb.serialize() tb.serialize()
......
...@@ -44,6 +44,10 @@ class CythonDebugWriter(object): ...@@ -44,6 +44,10 @@ class CythonDebugWriter(object):
def end(self, name): def end(self, name):
self.tb.end(name) self.tb.end(name)
def add_entry(self, name, **attrs):
self.tb.start(name, attrs)
self.tb.end(name)
def serialize(self): def serialize(self):
self.tb.end('Module') self.tb.end('Module')
self.tb.end('cython_debug') self.tb.end('cython_debug')
......
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