From 1e3926e5c65e4e01b22f9b1198caa1ae31e44c42 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sun, 22 Dec 2019 08:13:02 +0100 Subject: Remove redundant 'node.next = None' assignment for the last node in a file A node already gets its .next pointer set in _parse_block() if it is either 1. followed by another node, or 2. the last node in a menu, choice, or if. This also works for nodes from 'source'd files, so there's no need to special-case the ends of them. Remove the 'node.next = None' assignment for ends of files. Instead, special-case just the last node in all files, and set its .next to None in Kconfig._init(). Unlikely to give a noticeable performance improvement. Just tightens up the chaining logic a bit. --- kconfiglib.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'kconfiglib.py') diff --git a/kconfiglib.py b/kconfiglib.py index 6b5e99b..4be2d5c 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -1080,8 +1080,9 @@ class Kconfig(object): self._readline = self._open(join(self.srctree, filename), "r").readline try: - # Parse the Kconfig files - self._parse_block(None, self.top_node, self.top_node) + # Parse the Kconfig files. Returns the last node, which we + # terminate with '.next = None'. + self._parse_block(None, self.top_node, self.top_node).next = None self.top_node.list = self.top_node.next self.top_node.next = None except UnicodeDecodeError as e: @@ -3086,7 +3087,7 @@ class Kconfig(object): "no corresponding 'menu'" if t0 is _T_ENDMENU else "unrecognized construct") - # End of file reached. Terminate the final node and return it. + # End of file reached. Return the last node. if end_token: raise KconfigError( @@ -3096,7 +3097,6 @@ class Kconfig(object): "endmenu", self.filename)) - prev.next = None return prev def _parse_cond(self): -- cgit v1.2.3