Skip to content

Commit aff4e09

Browse files
committed
Use where instead of filter for for loops
With swiftlang/swift-syntax#1958, `node.filter` will return a new `SyntaxCollection` that has the filtered elements removed (instead of the array it’s currently returning). Since that node has elements removed, it will have a new parent and thus all the nodes inside of it have new IDs. Use `where` after `for` to get the elements with the same IDs and just don’t iterate the elements that don’t satisfy the condition. This is also more performant because it doesn’t create an intermediate array.
1 parent d16d7de commit aff4e09

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
744744

745745
// An if-configuration clause around a switch-case encloses the case's node, so an
746746
// if-configuration clause requires a break here in order to be allowed on a new line.
747-
for ifConfigDecl in node.cases.filter({ $0.is(IfConfigDeclSyntax.self) }) {
747+
for ifConfigDecl in node.cases where ifConfigDecl.is(IfConfigDeclSyntax.self) {
748748
if config.indentSwitchCaseLabels {
749749
before(ifConfigDecl.firstToken(viewMode: .sourceAccurate), tokens: .break(.open))
750750
after(ifConfigDecl.lastToken(viewMode: .sourceAccurate), tokens: .break(.close, size: 0))

0 commit comments

Comments
 (0)