Skip to content

Commit ef8bb05

Browse files
committed
[SyntaxRewriter] Return the node as-is
There's no performance reason to return 'nil'
1 parent 7298fe8 commit ef8bb05

File tree

2 files changed

+289
-289
lines changed

2 files changed

+289
-289
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
160160
/// - Returns: the rewritten node
161161
\(node.apiAttributes())\
162162
open func visit(_ node: \(node.kind.syntaxType)) -> \(node.kind.syntaxType) {
163-
return visitChildren(node._syntaxNode)?.cast(\(node.kind.syntaxType).self) ?? node
163+
return visitChildren(node._syntaxNode).cast(\(node.kind.syntaxType).self)
164164
}
165165
"""
166166
)
@@ -172,7 +172,7 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
172172
/// - Returns: the rewritten node
173173
\(node.apiAttributes())\
174174
open func visit(_ node: \(node.kind.syntaxType)) -> \(node.baseType.syntaxBaseName) {
175-
return \(node.baseType.syntaxBaseName)(visitChildren(node._syntaxNode)?.cast(\(node.kind.syntaxType).self) ?? node)
175+
return \(node.baseType.syntaxBaseName)(visitChildren(node._syntaxNode).cast(\(node.kind.syntaxType).self))
176176
}
177177
"""
178178
)
@@ -302,7 +302,7 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
302302

303303
DeclSyntax(
304304
"""
305-
private func visitChildren(_ node: Syntax) -> Syntax? {
305+
private func visitChildren(_ node: Syntax) -> Syntax {
306306
// Walk over all children of this node and rewrite them. Don't store any
307307
// rewritten nodes until the first non-`nil` value is encountered. When this
308308
// happens, retrieve all previous syntax nodes from the parent node to
@@ -357,7 +357,7 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
357357
}
358358
} else {
359359
// No child node was rewritten. So no need to change this node as well.
360-
return nil
360+
return node
361361
}
362362
}
363363
"""

0 commit comments

Comments
 (0)