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

Commit 6dabf495 authored by Eckhart Arnold's avatar Eckhart Arnold

- syntaxtree.py: Node: __slots__ added for memory optimization; need to optimize caching

parent 79f5bbdd
......@@ -260,8 +260,7 @@ def add_parser_guard(parser_func):
node, rest = parser_func(parser, text)
if node is None:
# retrieve an earlier match result (from left recursion)
# if it exists
# retrieve an earlier match result (from left recursion) if it exists
node, rest = parser.visited.get(location, (None, rest))
# don't overwrite any positive match (i.e. node not None) in the cache
# and don't add empty entries for parsers returning from left recursive calls!
......
......@@ -187,12 +187,15 @@ class Node:
AST-transformation.
"""
__slots__ = ['_result', 'children', '_errors', '_len', '_pos', 'parser', 'error_flag']
def __init__(self, parser, result: ResultType) -> None:
"""Initializes the ``Node``-object with the ``Parser``-Instance
that generated the node and the parser's result.
"""
# self._result = '' # type: StrictResultType
# self.children = () # type: ChildrenType
# self.error_flag = False # type: bool
self._errors = [] # type: List[str]
self.result = result
self._len = len(result) if not self.children else \
......@@ -481,6 +484,11 @@ class Node:
# return nav(path.split('/'))
def tree_size(self) -> int:
"""Recursively counts the number of nodes in the tree including the root node."""
return sum(child.tree_size() for child in self.children) + 1
def log(self, log_file_name):
if is_logging():
path = os.path.join(log_dir(), log_file_name)
......
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