Skip to content

Commit 6af545b

Browse files
authored
Merge pull request robotpy#51 from robotpy/defer-fmt
Format string performance things
2 parents 066706e + b60b0f2 commit 6af545b

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

CppHeaderParser/CppHeaderParser.py

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ def warning_print(fmt, *args):
100100

101101
if debug:
102102

103+
class _debug_caller_lineno:
104+
def __str__(self):
105+
return str(inspect.currentframe().f_back.f_back.f_back.f_lineno)
106+
107+
debug_caller_lineno = _debug_caller_lineno()
108+
103109
def debug_print(fmt, *args):
104110
fmt = "[%4d] " + fmt
105111
args = (inspect.currentframe().f_back.f_lineno,) + args
@@ -108,16 +114,18 @@ def debug_print(fmt, *args):
108114

109115
else:
110116

117+
debug_caller_lineno = None
118+
111119
def debug_print(fmt, *args):
112120
pass
113121

114122

115123
if debug_trace:
116124

117125
def trace_print(*args):
118-
sys.stdout.write("[%s] " % (inspect.currentframe().f_back.f_lineno))
126+
sys.stdout.write("[%s]" % (inspect.currentframe().f_back.f_lineno))
119127
for a in args:
120-
sys.stdout.write("%s " % a)
128+
sys.stdout.write(" %s" % a)
121129
sys.stdout.write("\n")
122130

123131

@@ -721,7 +729,7 @@ def __init__(self, nameStack, curTemplate, doxygen, location, defaultAccess):
721729

722730
if curTemplate:
723731
self["template"] = curTemplate
724-
trace_print("Setting template to '%s'" % self["template"])
732+
trace_print("Setting template to", self["template"])
725733

726734
methodAccessSpecificList = {}
727735
propertyAccessSpecificList = {}
@@ -1857,7 +1865,6 @@ def finalize_vars(self):
18571865
else:
18581866
trace_print("WARN-this should almost never happen!")
18591867
trace_print(var)
1860-
trace_print("-" * 80)
18611868
var["unresolved"] = True
18621869

18631870
elif tag in self._template_typenames:
@@ -1942,23 +1949,23 @@ def finalize_vars(self):
19421949
# var['raw_type'] = var['raw_type'][2:]
19431950

19441951
# Take care of #defines and #pragmas etc
1945-
trace_print("Processing precomp_macro_buf: %s" % self._precomp_macro_buf)
1952+
trace_print("Processing precomp_macro_buf:", self._precomp_macro_buf)
19461953
for m, location in self._precomp_macro_buf:
19471954
macro = m.replace("<CppHeaderParser_newline_temp_replacement>\\n", "\n")
19481955
ml = macro.lower()
19491956
try:
19501957
if ml.startswith("#define"):
1951-
trace_print("Adding #define %s" % macro)
1958+
trace_print("Adding #define", macro)
19521959
define = CppDefine(macro, location)
19531960
self.defines.append(define["value"])
19541961
self.defines_detail.append(define)
19551962
elif ml.startswith("#pragma"):
1956-
trace_print("Adding #pragma %s" % macro)
1963+
trace_print("Adding #pragma", macro)
19571964
pragma = CppPragma(macro, location)
19581965
self.pragmas_detail.append(pragma)
19591966
self.pragmas.append(pragma["value"])
19601967
elif ml.startswith("#include"):
1961-
trace_print("Adding #include %s" % macro)
1968+
trace_print("Adding #include", macro)
19621969
include = CppInclude(macro, location)
19631970
self.includes.append(include["value"])
19641971
self.includes_detail.append(include)
@@ -2447,8 +2454,9 @@ def _evaluate_property_stack(self, clearStack=True, addToVar=None):
24472454
# Is it really a list of variables?
24482455
if leftMostComma != 0:
24492456
trace_print(
2450-
"Multiple variables for namestack in %s. Separating processing"
2451-
% self.nameStack
2457+
"Multiple variables for namestack in",
2458+
self.nameStack,
2459+
". Separating processing",
24522460
)
24532461
orig_nameStack = self.nameStack[:]
24542462

@@ -2572,7 +2580,6 @@ def _evaluate_class_stack(self):
25722580
if key in self.classes:
25732581
trace_print("ERROR name collision:", key)
25742582
self.classes[key].show()
2575-
trace_print("-" * 80)
25762583
newClass.show()
25772584
assert key not in self.classes # namespace collision
25782585
self.classes[key] = newClass
@@ -3237,10 +3244,10 @@ def _evaluate_stack(self, token=None):
32373244
nameStackCopy = self.nameStack[:]
32383245

32393246
debug_print(
3240-
"Evaluating stack %s\n BraceDepth: %s (called from %d)",
3247+
"Evaluating stack %s\n BraceDepth: %s (called from %s)",
32413248
self.nameStack,
32423249
self.braceDepth,
3243-
inspect.currentframe().f_back.f_lineno,
3250+
debug_caller_lineno,
32443251
)
32453252

32463253
# Handle special case of overloading operator ()
@@ -3282,7 +3289,7 @@ def _evaluate_stack(self, token=None):
32823289
)
32833290
):
32843291
debug_print("trace")
3285-
trace_print("typedef %s", self.stack)
3292+
trace_print("typedef", self.stack)
32863293
self._evaluate_typedef()
32873294
return
32883295

@@ -3399,7 +3406,7 @@ def _evaluate_stack(self, token=None):
33993406
elif self.braceDepth > len(self.nameSpaces) + 1:
34003407
debug_print("trace")
34013408
else:
3402-
debug_print("Discarded statement %s" % (self.nameStack,))
3409+
debug_print("Discarded statement %s", self.nameStack)
34033410

34043411
try:
34053412
self.nameStackHistory[self.braceDepth] = (nameStackCopy, self.curClass)
@@ -3635,35 +3642,35 @@ def _strip_parent_keys(self):
36353642
obj_queue = [self]
36363643
while len(obj_queue):
36373644
obj = obj_queue.pop()
3638-
trace_print("pop %s type %s" % (obj, type(obj)))
3645+
trace_print("pop", obj, "type", type(obj))
36393646
try:
36403647
if "parent" in obj.keys():
36413648
del obj["parent"]
3642-
trace_print("Stripped parent from %s" % obj.keys())
3649+
trace_print("Stripped parent from", obj.keys())
36433650
except:
36443651
pass
36453652
try:
36463653
if "method" in obj.keys():
36473654
del obj["method"]
3648-
trace_print("Stripped method from %s" % obj.keys())
3655+
trace_print("Stripped method from", obj.keys())
36493656
except:
36503657
pass
36513658
# Figure out what sub types are one of ours
36523659
try:
36533660
if not hasattr(obj, "keys"):
36543661
obj = obj.__dict__
36553662
for k in obj.keys():
3656-
trace_print("-Try key %s" % (k))
3657-
trace_print("-type %s" % (type(obj[k])))
3663+
trace_print("-Try key", k)
3664+
trace_print("-type", type(obj[k]))
36583665
if k in ["nameStackHistory", "parent", "_public_typedefs"]:
36593666
continue
36603667
if type(obj[k]) == list:
36613668
for i in obj[k]:
3662-
trace_print("push l %s" % i)
3669+
trace_print("push l", i)
36633670
obj_queue.append(i)
36643671
elif type(obj[k]) == dict:
36653672
if len(obj):
3666-
trace_print("push d %s" % obj[k])
3673+
trace_print("push d", obj[k])
36673674
obj_queue.append(obj[k])
36683675
elif type(obj[k]) == type(type(0)):
36693676
if type(obj[k]) == int:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy