-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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 faster dictionaries traversing for AST Rules #2951
Conversation
2a7fb4d
to
1b45501
Compare
Generated by 🚫 Danger |
1b45501
to
f817351
Compare
5-15% faster across the board 👏 |
@jpsim just a sec there's a another place with the same logic |
…ersing dictionaries
Oh.. there are multiple places with this kind of structure traverse |
I'm thinking about some generic traverser |
@jpsim Okay, I'm done for now.
I will not be able to fix this in few next days. So feel free to update it, or just leave comments and I'll fix those. |
1a976c7
to
8aafd73
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! I tried seeing what it would look like to use map
instead of guard
as well, but prefer the guard
at the end.
@@ -46,6 +46,10 @@ | |||
[PaulTaykalo](https://github.com/PaulTaykalo) | |||
[#2949](https://github.com/realm/SwiftLint/issues/2949) | |||
|
|||
* Faster dictionaries traversing for AST Rules. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Speed up recursively executed rules (all AST rules and some others) by avoiding the creation of many intermediate collections when accumulating results.
@@ -151,6 +151,50 @@ public struct SourceKittenDictionary { | |||
} | |||
} | |||
|
|||
extension SourceKittenDictionary { | |||
/// Traversing all substuctures of the dictionary hierarchically, calling |traverseBlock| on each node. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: use markdown-style code markup using backticks instead of |
so it renders nicely in Xcode.
/// Traversing all substuctures of the dictionary hierarchically, calling |traverseBlock| on each node. | |
/// Traversing all substructures of the dictionary hierarchically, calling `traverseBlock` on each node. |
@@ -151,6 +151,50 @@ public struct SourceKittenDictionary { | |||
} | |||
} | |||
|
|||
extension SourceKittenDictionary { | |||
/// Traversing all substuctures of the dictionary hierarchically, calling |traverseBlock| on each node. | |||
/// Traversing using depth first strategy, so deepest substructures will be passed to |traversBlock| first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: traversBlock -> traverseBlock
return result | ||
} | ||
|
||
private func traverseDepthFirst<T>(collectingValuesInto array:inout [T], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: space between :
and inout
:
private func traverseDepthFirst<T>(collectingValuesInto array:inout [T], | |
private func traverseDepthFirst<T>(collectingValuesInto array: inout [T], |
} | ||
|
||
private func traverseWithParentDepthFirst<T>( | ||
collectingValuesInto array:inout [T], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: space between :
and inout
:
collectingValuesInto array:inout [T], | |
collectingValuesInto array: inout [T], |
Pushed this with minor edits to master because I'm cutting a release now 😄 |
No description provided.