Skip to content

Commit 514b0d8

Browse files
committed
Use a Set for duplicate name checks.
If there are a lot files generated, this linear check could have become an issue.
1 parent bf874e6 commit 514b0d8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Sources/SwiftProtobufPluginLibrary/CodeGenerator.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,13 @@ private final class InternalGeneratorOutputs: GeneratorOutputs {
250250
}
251251

252252
var files: [Google_Protobuf_Compiler_CodeGeneratorResponse.File] = []
253+
private var fileNames: Set<String> = []
253254

254255
func add(fileName: String, contents: String) throws {
255-
guard !files.contains(where: { $0.name == fileName }) else {
256+
guard !fileNames.contains(fileName) else {
256257
throw OutputError.duplicateName(fileName)
257258
}
259+
fileNames.insert(fileName)
258260
files.append(
259261
Google_Protobuf_Compiler_CodeGeneratorResponse.File(
260262
name: fileName,

0 commit comments

Comments
 (0)