@@ -5,6 +5,7 @@ public class SwiftAstGenerator {
55 private var srcDir : URL
66 private var outputDir : URL
77 private var prettyPrint : Bool
8+ private let availableProcessors = ProcessInfo . processInfo. activeProcessorCount
89
910 public init ( srcDir: URL , outputDir: URL , prettyPrint: Bool ) throws {
1011 self . srcDir = srcDir
@@ -43,13 +44,13 @@ public class SwiftAstGenerator {
4344 . appendingPathExtension ( " json " )
4445 let outfileDirUrl = outFileUrl. deletingLastPathComponent ( )
4546
46- if !FileManager . default . fileExists ( atPath : outfileDirUrl . path ) {
47+ do {
4748 try FileManager . default. createDirectory (
4849 atPath: outfileDirUrl. path,
4950 withIntermediateDirectories: true ,
5051 attributes: nil
5152 )
52- }
53+ } catch { }
5354
5455 try astJsonString. write (
5556 to: outFileUrl,
@@ -64,6 +65,11 @@ public class SwiftAstGenerator {
6465 }
6566
6667 private func iterateSwiftFiles( at url: URL ) {
68+ let queue = OperationQueue ( )
69+ queue. name = " SwiftAstGen "
70+ queue. qualityOfService = . userInitiated
71+ queue. maxConcurrentOperationCount = availableProcessors
72+
6773 if let enumerator = FileManager . default. enumerator (
6874 at: url,
6975 includingPropertiesForKeys: [ . isRegularFileKey] ,
@@ -73,11 +79,15 @@ public class SwiftAstGenerator {
7379 if fileAttributes. isRegularFile! && fileURL. pathExtension == " swift " {
7480 let relativeFilePath = fileURL. relativePath ( from: srcDir) !
7581 if !ignoreDirectory( name: " / \( relativeFilePath) " ) {
76- parseFile ( fileUrl: fileURL)
82+ queue. addOperation {
83+ self . parseFile ( fileUrl: fileURL)
84+ }
7785 }
7886 }
7987 }
8088 }
89+
90+ queue. waitUntilAllOperationsAreFinished ( )
8191 }
8292
8393 public func generate( ) throws {
0 commit comments