Commit 3c82deac authored by Stefan Behnel's avatar Stefan Behnel

reduce generated code size a bit by discarding end-of-line whitespace from multi-line C macros

parent 2fc964bc
...@@ -14,9 +14,10 @@ cython.declare(os=object, re=object, operator=object, ...@@ -14,9 +14,10 @@ cython.declare(os=object, re=object, operator=object,
import os import os
import re import re
import sys import sys
from string import Template
import operator import operator
import textwrap import textwrap
from string import Template
from functools import partial
try: try:
import hashlib import hashlib
...@@ -152,9 +153,11 @@ class UtilityCodeBase(object): ...@@ -152,9 +153,11 @@ class UtilityCodeBase(object):
if ext in ('.pyx', '.py', '.pxd', '.pxi'): if ext in ('.pyx', '.py', '.pxd', '.pxi'):
comment = '#' comment = '#'
replace_comments = re.compile(r'^\s*#.*').sub replace_comments = re.compile(r'^\s*#.*').sub
rstrip = unicode.rstrip
else: else:
comment = '/' comment = '/'
replace_comments = re.compile(r'^\s*//.*|/\*[^*]*\*/').sub replace_comments = re.compile(r'^\s*//.*|/\*[^*]*\*/').sub
rstrip = partial(re.compile(r'\s*(\\?)$').sub, r'\1')
match_special = re.compile( match_special = re.compile(
(r'^%(C)s{5,30}\s*(?P<name>(?:\w|\.)+)\s*%(C)s{5,30}|' (r'^%(C)s{5,30}\s*(?P<name>(?:\w|\.)+)\s*%(C)s{5,30}|'
r'^%(C)s+@(?P<tag>\w+)\s*:\s*(?P<value>(?:\w|[.:])+)' r'^%(C)s+@(?P<tag>\w+)\s*:\s*(?P<value>(?:\w|[.:])+)'
...@@ -194,7 +197,7 @@ class UtilityCodeBase(object): ...@@ -194,7 +197,7 @@ class UtilityCodeBase(object):
tags.setdefault(m.group('tag'), set()).add(m.group('value')) tags.setdefault(m.group('tag'), set()).add(m.group('value'))
lines.append('') # keep line number correct lines.append('') # keep line number correct
else: else:
lines.append(replace_comments('', line).rstrip()) lines.append(rstrip(replace_comments('', line)))
if utility is None: if utility is None:
raise ValueError("Empty utility code file") raise ValueError("Empty utility code file")
......
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