@@ -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,27 +124,42 @@ 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 concurrentQueue = DispatchQueue (
133+ label: " swift-format-queue " , qos: . userInitiated, attributes: . concurrent)
134+ let lock = NSLock ( )
135+ let openAndProcess : ( String ) -> Void = { path in
133136 guard let sourceFile = FileHandle ( forReadingAtPath: path) else {
134- diagnosticEngine. diagnose ( Diagnostic . Message ( . error, " Unable to open \( path) " ) )
135- continue
137+ lock. lock ( )
138+ defer { lock. unlock ( ) }
139+ self . diagnosticEngine. diagnose ( Diagnostic . Message ( . error, " Unable to open \( path) " ) )
140+ return
136141 }
137142
138- guard let configuration = configuration (
139- atPath: lintFormatOptions. configurationPath, orInferredFromSwiftFileAtPath: path)
143+ guard let configuration = self . configuration (
144+ atPath: self . lintFormatOptions. configurationPath, orInferredFromSwiftFileAtPath: path)
140145 else {
141146 // Already diagnosed in the called method.
142- continue
147+ return
143148 }
144149
145150 let fileToProcess = FileToProcess (
146151 fileHandle: sourceFile, path: path, configuration: configuration)
147- processFile ( fileToProcess)
152+ self . processFile ( fileToProcess)
153+ }
154+
155+ for path in FileIterator ( paths: paths) {
156+ if parallel {
157+ concurrentQueue. async {
158+ openAndProcess ( path)
159+ }
160+ } else {
161+ openAndProcess ( path)
162+ }
148163 }
149164 }
150165
0 commit comments