@@ -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 concurrentQueue = DispatchQueue (
133
+ label: " swift-format-queue " , qos: . userInitiated, attributes: . concurrent)
134
+ let lock = NSLock ( )
135
+ let openAndProcess : ( String ) -> Void = { path in
133
136
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
136
141
}
137
142
138
- guard let configuration = configuration (
139
- atPath: lintFormatOptions. configurationPath, orInferredFromSwiftFileAtPath: path)
143
+ guard let configuration = self . configuration (
144
+ atPath: self . lintFormatOptions. configurationPath, orInferredFromSwiftFileAtPath: path)
140
145
else {
141
146
// Already diagnosed in the called method.
142
- continue
147
+ return
143
148
}
144
149
145
150
let fileToProcess = FileToProcess (
146
151
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
+ }
148
163
}
149
164
}
150
165
0 commit comments