Notice to GitKraken users: A vulnerability has been found in the SSH key generation of GitKraken versions 7.6.0 to 8.0.0 (https://www.gitkraken.com/blog/weak-ssh-key-fix). If you use GitKraken and have generated a SSH key using one of these versions, please remove it both from your local workstation and from your LRZ GitLab profile.

21.10.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit d1967501 authored by Eckhart Arnold's avatar Eckhart Arnold
Browse files

- syntax_tree.py: optimazation of traverse_recursive()

parent 25f7a814
...@@ -225,7 +225,7 @@ class Node: ...@@ -225,7 +225,7 @@ class Node:
other._pos = self._pos other._pos = self._pos
return other return other
@property @property # this needs to be a (dynamic) property, in case sef.parser gets updated
def tag_name(self) -> str: def tag_name(self) -> str:
return self.parser.name or self.parser.ptype return self.parser.name or self.parser.ptype
# ONLY FOR DEBUGGING: return self.parser.name + ':' + self.parser.ptype # ONLY FOR DEBUGGING: return self.parser.name + ':' + self.parser.ptype
...@@ -605,18 +605,26 @@ def traverse(root_node, processing_table, key_func=key_tag_name) -> None: ...@@ -605,18 +605,26 @@ def traverse(root_node, processing_table, key_func=key_tag_name) -> None:
# with a single value # with a single value
table = {name: smart_list(call) for name, call in list(processing_table.items())} table = {name: smart_list(call) for name, call in list(processing_table.items())}
table = expand_table(table) table = expand_table(table)
cache = {}
def traverse_recursive(node): def traverse_recursive(node):
if node.children: if node.children:
for child in node.result: for child in node.result:
traverse_recursive(child) # depth first traverse_recursive(child) # depth first
node.error_flag |= child.error_flag # propagate error flag node.error_flag |= child.error_flag # propagate error flag
key = key_func(node)
sequence = cache.get(key, None)
if sequence is None:
sequence = table.get('+', []) + \ sequence = table.get('+', []) + \
table.get(key_func(node), table.get('*', [])) + \ table.get(key, table.get('*', [])) + \
table.get('~', []) table.get('~', [])
# '+' always called (before any other processing function) # '+' always called (before any other processing function)
# '*' called for those nodes for which no (other) processing function appears in the table # '*' called for those nodes for which no (other) processing function
# appears in the table
# '~' always called (after any other processing function) # '~' always called (after any other processing function)
cache[key] = sequence
for call in sequence: for call in sequence:
call(node) call(node)
......
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