Skip to content

Commit

Permalink
Improve performance by moving contains check to async code
Browse files Browse the repository at this point in the history
  • Loading branch information
dfed committed Dec 10, 2023
1 parent a47f8c7 commit d609323
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions Sources/SafeDIPlugin/SafeDIPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct SafeDIPlugin: AsyncParsableCommand {

// MARK: Internal

@MainActor
func run() async throws {
async let dependentModuleInfo = try Self.findSafeDIModuleInfo(
atModuleInfoURLs: moduleInfoPaths.map(\.asFileURL)
Expand All @@ -71,6 +72,7 @@ struct SafeDIPlugin: AsyncParsableCommand {
}
}

@MainActor
static func run(
swiftFileContent: [String],
dependentImportStatements: [ImportStatement],
Expand Down Expand Up @@ -123,12 +125,20 @@ struct SafeDIPlugin: AsyncParsableCommand {
) { taskGroup in
for filePath in swiftFilePaths {
taskGroup.addTask {
try String(contentsOfFile: filePath)
let swiftFile = try String(contentsOfFile: filePath)
if swiftFile.contains(#"@Instantiable"#) {
return swiftFile
} else {
// We don't care about this file.
return ""
}
}
}
var swiftFiles = [String]()
for try await swiftFile in taskGroup {
swiftFiles.append(swiftFile)
if !swiftFile.isEmpty {
swiftFiles.append(swiftFile)
}
}
return swiftFiles
}
Expand All @@ -139,11 +149,6 @@ struct SafeDIPlugin: AsyncParsableCommand {
var instantiables = [Instantiable]()
var nestedInstantiableDecoratedTypeDescriptions = [TypeDescription]()
for content in swiftFileContent {
guard content.contains(#"@Instantiable"#) else {
// We don't care about this file.
continue
}

let fileVisitor = FileVisitor()
fileVisitor.walk(Parser.parse(source: content))
nestedInstantiableDecoratedTypeDescriptions.append(
Expand Down

0 comments on commit d609323

Please sign in to comment.