Skip to content

Commit

Permalink
Speed up "computed accessors order" rule
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulTaykalo committed Sep 30, 2021
1 parent e4ff164 commit acd8bb3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
[Marcelo Fabri](https://github.com/marcelofabri)
[#3724](https://github.com/realm/SwiftLint/issues/3724)

* Speed up Computed Accessors Order rule.
[PaulTaykalo](https://github.com/PaulTaykalo)
[#3727](https://github.com/realm/SwiftLint/issues/3727)

## 0.44.0: Travel Size Lint Roller

#### Breaking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public struct ComputedAccessorsOrderRule: ConfigurationProviderRule {
file: SwiftLintFile,
range: NSRange? = nil) -> [SwiftLintSyntaxToken] {
let pattern = "\\b\(keyword)\\b"
return file.rangesAndTokens(matching: pattern).compactMap { _, tokens in
return file.rangesAndTokens(matching: pattern, range: range).compactMap { _, tokens in
guard tokens.count == 1,
let token = tokens.last,
token.kind == .keyword else {
Expand All @@ -101,7 +101,9 @@ private extension ComputedAccessorsOrderRule {
let allowedKinds = SwiftDeclarationKind.variableKinds.subtracting([.varParameter])
.union([.functionSubscript])

func parse(dictionary: SourceKittenDictionary, parentKind: SwiftDeclarationKind?) {
func parse(dictionary: SourceKittenDictionary,
parentKind: SwiftDeclarationKind?,
into results: inout [SourceKittenDictionary]) {
// Only accepts declarations which contains a body and contains the
// searched byteOffset
guard let kind = dictionary.declarationKind,
Expand All @@ -116,13 +118,13 @@ private extension ComputedAccessorsOrderRule {
}

for dictionary in dictionary.substructure {
parse(dictionary: dictionary, parentKind: kind)
parse(dictionary: dictionary, parentKind: kind, into: &results)
}
}

let dict = structureDictionary
for dictionary in dict.substructure {
parse(dictionary: dictionary, parentKind: nil)
parse(dictionary: dictionary, parentKind: nil, into: &results)
}

return results
Expand Down

0 comments on commit acd8bb3

Please sign in to comment.