@@ -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,28 +124,46 @@ 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 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)
148
150
}
151
+
152
+ let concurrentQueue = DispatchQueue (
153
+ label: " swift-format-queue " , qos: . userInitiated, attributes: . concurrent)
154
+ let group = DispatchGroup ( )
155
+ let lock = NSLock ( )
156
+ for path in FileIterator ( paths: paths) {
157
+ if parallel {
158
+ concurrentQueue. async ( group: group) {
159
+ openAndProcess ( path, lock)
160
+ }
161
+ } else {
162
+ openAndProcess ( path, nil )
163
+ }
164
+ }
165
+
166
+ group. wait ( )
149
167
}
150
168
151
169
/// Returns the configuration that applies to the given `.swift` source file, when an explicit
0 commit comments