@@ -92,7 +92,7 @@ class Frontend {
92
92
if paths. isEmpty {
93
93
processStandardInput ( )
94
94
} else {
95
- processPaths ( paths)
95
+ processPaths ( paths, parallel : lintFormatOptions . parallel )
96
96
}
97
97
}
98
98
@@ -124,27 +124,42 @@ class Frontend {
124
124
}
125
125
126
126
/// Processes source content from a list of files and/or directories provided as paths.
127
- private func processPaths( _ paths: [ String ] ) {
127
+ private func processPaths( _ paths: [ String ] , parallel : Bool ) {
128
128
precondition (
129
129
!paths. isEmpty,
130
130
" processPaths(_:) should only be called when paths is non-empty. " )
131
131
132
- for path in FileIterator ( paths : paths ) {
132
+ let openAndProcess : ( String , NSLock ? ) -> Void = { path , lock in
133
133
guard let sourceFile = FileHandle ( forReadingAtPath: path) else {
134
- diagnosticEngine. diagnose ( Diagnostic . Message ( . error, " Unable to open \( path) " ) )
135
- continue
134
+ lock? . lock ( )
135
+ defer { lock? . unlock ( ) }
136
+ self . diagnosticEngine. diagnose ( Diagnostic . Message ( . error, " Unable to open \( path) " ) )
137
+ return
136
138
}
137
139
138
- guard let configuration = configuration (
139
- atPath: lintFormatOptions. configurationPath, orInferredFromSwiftFileAtPath: path)
140
+ guard let configuration = self . configuration (
141
+ atPath: self . lintFormatOptions. configurationPath, orInferredFromSwiftFileAtPath: path)
140
142
else {
141
143
// Already diagnosed in the called method.
142
- continue
144
+ return
143
145
}
144
146
145
147
let fileToProcess = FileToProcess (
146
148
fileHandle: sourceFile, path: path, configuration: configuration)
147
- processFile ( fileToProcess)
149
+ self . processFile ( fileToProcess)
150
+ }
151
+
152
+ let lock = NSLock ( )
153
+ let allFilePaths = Array ( FileIterator ( paths: paths) )
154
+ if parallel {
155
+ DispatchQueue . concurrentPerform ( iterations: allFilePaths. count) { index in
156
+ let path = allFilePaths [ index]
157
+ openAndProcess ( path, lock)
158
+ }
159
+ } else {
160
+ for path in allFilePaths {
161
+ openAndProcess ( path, nil )
162
+ }
148
163
}
149
164
}
150
165
0 commit comments