@@ -92,7 +92,7 @@ class Frontend {
9292 if paths. isEmpty {
9393 processStandardInput ( )
9494 } else {
95- processPaths ( paths)
95+ processPaths ( paths, parallel : lintFormatOptions . parallel )
9696 }
9797 }
9898
@@ -124,28 +124,46 @@ class Frontend {
124124 }
125125
126126 /// 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 ) {
128128 precondition (
129129 !paths. isEmpty,
130130 " processPaths(_:) should only be called when paths is non-empty. " )
131131
132- for path in FileIterator ( paths : paths ) {
132+ let openAndProcess : ( String , NSLock ? ) -> Void = { path in
133133 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
136138 }
137139
138- guard let configuration = configuration (
139- atPath: lintFormatOptions. configurationPath, orInferredFromSwiftFileAtPath: path)
140+ guard let configuration = self . configuration (
141+ atPath: self . lintFormatOptions. configurationPath, orInferredFromSwiftFileAtPath: path)
140142 else {
141143 // Already diagnosed in the called method.
142- continue
144+ return
143145 }
144146
145147 let fileToProcess = FileToProcess (
146148 fileHandle: sourceFile, path: path, configuration: configuration)
147- processFile ( fileToProcess)
149+ self . processFile ( fileToProcess)
148150 }
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 ( )
149167 }
150168
151169 /// Returns the configuration that applies to the given `.swift` source file, when an explicit
0 commit comments