Skip to content

Commit 4990314

Browse files
committed
avoid duplicate initializations
1 parent 8478d15 commit 4990314

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

nuget/Sqlite_net.SourceGenerator/SQLiteFastColumnSetterGenerator.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,9 @@ static void Execute(
335335
{
336336
if (classes.IsDefaultOrEmpty)
337337
return;
338-
338+
339+
classes = RemoveDuplicates(classes);
340+
339341
// Get the assembly name/namespace from the compilation
340342
var assemblyName = compilation.AssemblyName ?? "Generated";
341343
var rootNamespace = GetRootNamespace(configOptionsProvider, compilation) ?? assemblyName;
@@ -393,6 +395,25 @@ static void Execute(
393395
context.AddSource("SQLiteInitializer.g.cs", SourceText.From(sb.ToString(), Encoding.UTF8));
394396
}
395397

398+
private static ImmutableArray<ClassInfo> RemoveDuplicates (ImmutableArray<ClassInfo> classes)
399+
{
400+
Dictionary<string, ClassInfo> existing = new();
401+
402+
foreach (var it in classes) {
403+
var fullTypeName = FullTypeName (it);
404+
if (existing.TryGetValue (fullTypeName, out var current)) {
405+
if (it.Properties.Count > current.Properties.Count) {
406+
existing[fullTypeName] = it;
407+
}
408+
}
409+
else {
410+
existing[fullTypeName] = it;
411+
}
412+
}
413+
414+
return existing.Values.ToImmutableArray();
415+
}
416+
396417
static string FullTypeName (ClassInfo classInfo)
397418
{
398419
return string.IsNullOrEmpty (classInfo.Namespace)

0 commit comments

Comments
 (0)