File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change 10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
+ import Foundation
14
+
13
15
/// A Rule is a linting or formatting pass that executes in a given context.
14
16
public protocol Rule {
15
17
/// The context in which the rule is executed.
@@ -26,16 +28,26 @@ public protocol Rule {
26
28
}
27
29
28
30
fileprivate var nameCache = [ ObjectIdentifier: String] ( )
31
+ fileprivate var nameCacheQueue = DispatchQueue (
32
+ label: " com.apple.SwiftFormat.NameCache " , attributes: . concurrent)
29
33
30
34
extension Rule {
31
35
/// By default, the `ruleName` is just the name of the implementing rule class.
32
36
public static var ruleName : String {
33
37
let identifier = ObjectIdentifier ( self )
34
- if let cachedName = nameCache [ identifier] {
38
+ let cachedName = nameCacheQueue. sync {
39
+ nameCache [ identifier]
40
+ }
41
+
42
+ if let cachedName = cachedName {
35
43
return cachedName
36
44
}
45
+
37
46
let name = String ( " \( self ) " . split ( separator: " . " ) . last!)
38
- nameCache [ identifier] = name
47
+ nameCacheQueue. async ( flags: . barrier) {
48
+ nameCache [ identifier] = name
49
+ }
50
+
39
51
return name
40
52
}
41
53
}
You can’t perform that action at this time.
0 commit comments