Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use where instead of filter for for loops #575

Merged

Conversation

ahoppen
Copy link
Contributor

@ahoppen ahoppen commented Jul 27, 2023

Companion of swiftlang/swift-syntax#1958

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.

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.
@ahoppen ahoppen force-pushed the ahoppen/syntax-collection-range-replaceable branch from 6500185 to aff4e09 Compare July 28, 2023 14:43
@ahoppen ahoppen merged commit 243db9e into swiftlang:main Aug 1, 2023
@ahoppen ahoppen deleted the ahoppen/syntax-collection-range-replaceable branch August 1, 2023 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants