Notice to GitKraken users: A vulnerability has been found in the SSH key generation of GitKraken versions 7.6.0 to 8.0.0 ( 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 9e1686d9 authored by Eckhart Arnold's avatar Eckhart Arnold
Browse files

- DHParser/ Node.content optimized so as to minimize string copy operations

parent af07a4db
......@@ -354,6 +354,18 @@ class Node: # ( Base class omitted for cython-compatibil
self.children = NoChildren
self._result = result # cast(StrictResultType, result)
def _content(self) -> List[str]:
Returns string content as list of string fragments
that are gathered from all child nodes in order.
if self.children:
fragments = []
for child in self.children:
return fragments
self._result = str(self._result)
return [self._result]
def content(self) -> str:
......@@ -362,7 +374,11 @@ class Node: # ( Base class omitted for cython-compatibil
string content of the child-nodes is recursively read and then
return "".join(child.content for child in self.children) if self.children else str(self._result)
return ''.join(self._content())
## unoptimized
# return "".join(child.content for child in self.children) if self.children else str(
# self._result)
## obsolete
# if self._content is None:
# if self.children:
# self._content = "".join(child.content for child in self.children)
......@@ -81,6 +81,17 @@ class TestNode:
self.recurring_nodes_sexpr = '(a (b x) (c (d e) (b y)))'
self.recurr_tree = parse_sxpr(self.recurring_nodes_sexpr)
def test_content_property(self):
tree = RootNode(parse_sxpr('(a (b c) (d e))'))
content = tree.content
b = tree.pick('b')
d = tree.pick('d')
b.result = "recently "
d.result = "changed"
assert content != tree.content
assert content == 'ce'
assert tree.content == 'recently changed'
def test_deepcopy(self):
tree = RootNode(parse_sxpr('(a (b c) (d (e f) (h i)))'))
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