Skip to content

Format string performance things #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 29 additions & 22 deletions CppHeaderParser/CppHeaderParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ def warning_print(fmt, *args):

if debug:

class _debug_caller_lineno:
def __str__(self):
return str(inspect.currentframe().f_back.f_back.f_back.f_lineno)

debug_caller_lineno = _debug_caller_lineno()

def debug_print(fmt, *args):
fmt = "[%4d] " + fmt
args = (inspect.currentframe().f_back.f_lineno,) + args
Expand All @@ -108,16 +114,18 @@ def debug_print(fmt, *args):

else:

debug_caller_lineno = None

def debug_print(fmt, *args):
pass


if debug_trace:

def trace_print(*args):
sys.stdout.write("[%s] " % (inspect.currentframe().f_back.f_lineno))
sys.stdout.write("[%s]" % (inspect.currentframe().f_back.f_lineno))
for a in args:
sys.stdout.write("%s " % a)
sys.stdout.write(" %s" % a)
sys.stdout.write("\n")


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

if curTemplate:
self["template"] = curTemplate
trace_print("Setting template to '%s'" % self["template"])
trace_print("Setting template to", self["template"])

methodAccessSpecificList = {}
propertyAccessSpecificList = {}
Expand Down Expand Up @@ -1857,7 +1865,6 @@ def finalize_vars(self):
else:
trace_print("WARN-this should almost never happen!")
trace_print(var)
trace_print("-" * 80)
var["unresolved"] = True

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

# Take care of #defines and #pragmas etc
trace_print("Processing precomp_macro_buf: %s" % self._precomp_macro_buf)
trace_print("Processing precomp_macro_buf:", self._precomp_macro_buf)
for m, location in self._precomp_macro_buf:
macro = m.replace("<CppHeaderParser_newline_temp_replacement>\\n", "\n")
ml = macro.lower()
try:
if ml.startswith("#define"):
trace_print("Adding #define %s" % macro)
trace_print("Adding #define", macro)
define = CppDefine(macro, location)
self.defines.append(define["value"])
self.defines_detail.append(define)
elif ml.startswith("#pragma"):
trace_print("Adding #pragma %s" % macro)
trace_print("Adding #pragma", macro)
pragma = CppPragma(macro, location)
self.pragmas_detail.append(pragma)
self.pragmas.append(pragma["value"])
elif ml.startswith("#include"):
trace_print("Adding #include %s" % macro)
trace_print("Adding #include", macro)
include = CppInclude(macro, location)
self.includes.append(include["value"])
self.includes_detail.append(include)
Expand Down Expand Up @@ -2447,8 +2454,9 @@ def _evaluate_property_stack(self, clearStack=True, addToVar=None):
# Is it really a list of variables?
if leftMostComma != 0:
trace_print(
"Multiple variables for namestack in %s. Separating processing"
% self.nameStack
"Multiple variables for namestack in",
self.nameStack,
". Separating processing",
)
orig_nameStack = self.nameStack[:]

Expand Down Expand Up @@ -2572,7 +2580,6 @@ def _evaluate_class_stack(self):
if key in self.classes:
trace_print("ERROR name collision:", key)
self.classes[key].show()
trace_print("-" * 80)
newClass.show()
assert key not in self.classes # namespace collision
self.classes[key] = newClass
Expand Down Expand Up @@ -3237,10 +3244,10 @@ def _evaluate_stack(self, token=None):
nameStackCopy = self.nameStack[:]

debug_print(
"Evaluating stack %s\n BraceDepth: %s (called from %d)",
"Evaluating stack %s\n BraceDepth: %s (called from %s)",
self.nameStack,
self.braceDepth,
inspect.currentframe().f_back.f_lineno,
debug_caller_lineno,
)

# Handle special case of overloading operator ()
Expand Down Expand Up @@ -3282,7 +3289,7 @@ def _evaluate_stack(self, token=None):
)
):
debug_print("trace")
trace_print("typedef %s", self.stack)
trace_print("typedef", self.stack)
self._evaluate_typedef()
return

Expand Down Expand Up @@ -3399,7 +3406,7 @@ def _evaluate_stack(self, token=None):
elif self.braceDepth > len(self.nameSpaces) + 1:
debug_print("trace")
else:
debug_print("Discarded statement %s" % (self.nameStack,))
debug_print("Discarded statement %s", self.nameStack)

try:
self.nameStackHistory[self.braceDepth] = (nameStackCopy, self.curClass)
Expand Down Expand Up @@ -3635,35 +3642,35 @@ def _strip_parent_keys(self):
obj_queue = [self]
while len(obj_queue):
obj = obj_queue.pop()
trace_print("pop %s type %s" % (obj, type(obj)))
trace_print("pop", obj, "type", type(obj))
try:
if "parent" in obj.keys():
del obj["parent"]
trace_print("Stripped parent from %s" % obj.keys())
trace_print("Stripped parent from", obj.keys())
except:
pass
try:
if "method" in obj.keys():
del obj["method"]
trace_print("Stripped method from %s" % obj.keys())
trace_print("Stripped method from", obj.keys())
except:
pass
# Figure out what sub types are one of ours
try:
if not hasattr(obj, "keys"):
obj = obj.__dict__
for k in obj.keys():
trace_print("-Try key %s" % (k))
trace_print("-type %s" % (type(obj[k])))
trace_print("-Try key", k)
trace_print("-type", type(obj[k]))
if k in ["nameStackHistory", "parent", "_public_typedefs"]:
continue
if type(obj[k]) == list:
for i in obj[k]:
trace_print("push l %s" % i)
trace_print("push l", i)
obj_queue.append(i)
elif type(obj[k]) == dict:
if len(obj):
trace_print("push d %s" % obj[k])
trace_print("push d", obj[k])
obj_queue.append(obj[k])
elif type(obj[k]) == type(type(0)):
if type(obj[k]) == int:
Expand Down