@@ -80,18 +80,34 @@ fileprivate func main(_ arguments: [String]) -> Int32 {
80
80
/// - transform: A closure that performs a transformation on a specific source file.
81
81
fileprivate func processSources(
82
82
from paths: [ String ] , configurationPath: String ? , diagnosticEngine: DiagnosticEngine ,
83
- transform: ( FileHandle , String , Configuration ) -> Int
83
+ transform: @escaping ( FileHandle , String , Configuration ) -> Int
84
84
) -> Int32 {
85
85
var result = 0
86
+ let concurrentQueue = DispatchQueue ( label: " com.queue.Concurrent " , qos: . userInitiated, attributes: . concurrent)
87
+ let group = DispatchGroup ( )
88
+ let lock = NSLock ( )
86
89
for path in FileIterator ( paths: paths) {
87
- guard let sourceFile = FileHandle ( forReadingAtPath: path) else {
88
- diagnosticEngine. diagnose (
89
- Diagnostic . Message ( . error, " Unable to create a file handle for source from \( path) . " ) )
90
- return 1
90
+ concurrentQueue. async ( group: group) {
91
+ guard let sourceFile = FileHandle ( forReadingAtPath: path) else {
92
+ diagnosticEngine. diagnose (
93
+ Diagnostic . Message ( . error, " Unable to create a file handle for source from \( path) . " ) )
94
+ lock. lock ( )
95
+ result |= 1
96
+ lock. unlock ( )
97
+ return
98
+ }
99
+
100
+ let configuration = loadConfiguration ( forSwiftFile: path, configFilePath: configurationPath)
101
+ let transformResult = transform ( sourceFile, path, configuration)
102
+ if transformResult > 0 {
103
+ lock. lock ( )
104
+ result |= transformResult
105
+ lock. unlock ( )
106
+ }
91
107
}
92
- let configuration = loadConfiguration ( forSwiftFile: path, configFilePath: configurationPath)
93
- result |= transform ( sourceFile, path, configuration)
94
108
}
109
+
110
+ group. wait ( )
95
111
return Int32 ( result)
96
112
}
97
113
0 commit comments