@@ -43,7 +43,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
43
43
44
44
/// Lists the expressions that have been visited, from the outermost expression, where contextual
45
45
/// breaks and start/end contextual breaking tokens have been inserted.
46
- private var preVisitedExprs = [ ExprSyntax] ( )
46
+ private var preVisitedExprs = Set < ExprSyntax > ( )
47
47
48
48
/// Lists the tokens that are the closing or final delimiter of a node that shouldn't be split
49
49
/// from the preceding token. When breaks are inserted around compound expressions, the breaks are
@@ -3181,20 +3181,13 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
3181
3181
/// necessary for contextual breaking throughout the expression. Records the nodes that were
3182
3182
/// visited so that they can be skipped later.
3183
3183
private func preVisitInsertingContextualBreaks< T: ExprSyntaxProtocol & Equatable > ( _ expr: T ) {
3184
- if !hasPreVisited( expr) {
3185
- let ( visited, _, _) = insertContextualBreaks ( ExprSyntax ( expr) , isTopLevel: true )
3186
- preVisitedExprs. append ( contentsOf: visited)
3184
+ let exprSyntax = ExprSyntax ( expr)
3185
+ if !preVisitedExprs. contains ( exprSyntax) {
3186
+ let ( visited, _, _) = insertContextualBreaks ( exprSyntax, isTopLevel: true )
3187
+ preVisitedExprs. formUnion ( visited)
3187
3188
}
3188
3189
}
3189
3190
3190
- /// Returns whether the given expression node has been pre-visited, from a parent expression.
3191
- private func hasPreVisited< T: ExprSyntaxProtocol & Equatable > ( _ expr: T ) -> Bool {
3192
- for item in preVisitedExprs {
3193
- if item == ExprSyntax ( expr) { return true }
3194
- }
3195
- return false
3196
- }
3197
-
3198
3191
/// Recursively visits nested expressions from the given expression inserting contextual breaking
3199
3192
/// tokens. When visiting an expression node, `preVisitInsertingContextualBreaks(_:)` should be
3200
3193
/// called instead of this helper.
0 commit comments