Skip to content

Commit 92dbbf8

Browse files
committed
[SyntaxNode] Make 'static var structure' immutable stored properties
Returnning array literal from computed property allocates and initializes the array buffer every time it's called, and they are deallocated after use. Make them stored properties so they stay in memory.
1 parent 70e3741 commit 92dbbf8

File tree

10 files changed

+2094
-2561
lines changed

10 files changed

+2094
-2561
lines changed

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodesFile.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,17 +199,14 @@ func syntaxNode(nodesStartingWith: [Character]) -> SourceFileSyntax {
199199
}
200200
}
201201

202-
try! VariableDeclSyntax("public static var structure: SyntaxNodeStructure") {
203-
let layout = ArrayExprSyntax {
204-
for child in node.children {
205-
ArrayElementSyntax(
206-
expression: ExprSyntax(#"\Self.\#(child.varOrCaseName)"#)
207-
)
208-
}
202+
let layout = ArrayExprSyntax {
203+
for child in node.children {
204+
ArrayElementSyntax(
205+
expression: ExprSyntax(#"\Self.\#(child.varOrCaseName)"#)
206+
)
209207
}
210-
211-
StmtSyntax("return .layout(\(layout))")
212208
}
209+
"public static let structure: SyntaxNodeStructure = .layout(\(layout))"
213210
}
214211
}
215212
}

0 commit comments

Comments
 (0)