Skip to content

Commit

Permalink
Memoize kind in Simplesect Node
Browse files Browse the repository at this point in the history
Rather than repeatedly loading the kind from the node's attributes,
fetch it once and then switch on the resulting value multiple times.
  • Loading branch information
mudge committed Aug 21, 2024
1 parent c7096f1 commit 09e14b6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,9 @@ class SimplesectNode(Node):
def to_asciidoc(self, **kwargs):
previous_node = self.previous_node()
next_node = self.next_node()
if self.node.get("kind") == "see":
kind = self.node.get("kind")

if kind == "see":
output = []
if not (
previous_node
Expand All @@ -662,10 +664,10 @@ def to_asciidoc(self, **kwargs):
output.append("\n--")
return "".join(output)

if self.node.get("kind") == "return":
if kind == "return":
return f"--\n*Returns*\n\n{super().to_asciidoc(**kwargs)}\n--"

if self.node.get("kind") == "note":
if kind == "note":
output = []
if not (
previous_node
Expand Down

0 comments on commit 09e14b6

Please sign in to comment.