Skip to content

Commit 308418f

Browse files
authored
Merge pull request #197 from dylansturg/better_rulename_cache
Actually cache rule names.
2 parents e1e5c0c + 13fd74d commit 308418f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Sources/SwiftFormatCore/Rule.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ fileprivate var nameCache = [ObjectIdentifier: String]()
2727
extension Rule {
2828
/// By default, the `ruleName` is just the name of the implementing rule class.
2929
public static var ruleName: String {
30-
return nameCache[
31-
ObjectIdentifier(self),
32-
default: String("\(self)".split(separator: ".").last!)
33-
]
30+
let identifier = ObjectIdentifier(self)
31+
if let cachedName = nameCache[identifier] {
32+
return cachedName
33+
}
34+
let name = String("\(self)".split(separator: ".").last!)
35+
nameCache[identifier] = name
36+
return name
3437
}
3538
}

0 commit comments

Comments
 (0)