Optimize NpgsqlConnectionStringBuilder AOT size (#4943) · npgsql/npgsql@f262fd1 · GitHub
Skip to content

Commit f262fd1

Browse files
authored
Optimize NpgsqlConnectionStringBuilder AOT size (#4943)
1 parent e8f20a0 commit f262fd1

3 files changed

Lines changed: 113 additions & 108 deletions

File tree

‎src/Npgsql.SourceGenerators/NpgsqlConnectionStringBuilder.snbtxt‎

Lines changed: 50 additions & 82 deletions

‎src/Npgsql.SourceGenerators/NpgsqlConnectionStringBuilderSourceGenerator.cs‎

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Linq;
34
using System.Text;
@@ -89,11 +90,24 @@ public void Execute(GeneratorExecutionContext context)
8990

9091
propertiesByKeyword[displayName.ToUpperInvariant()] = propertyDetails;
9192
if (property.Name != displayName)
92-
propertiesByKeyword[property.Name.ToUpperInvariant()] = propertyDetails;
93+
{
94+
var propertyName = property.Name.ToUpperInvariant();
95+
if (!propertiesByKeyword.ContainsKey(propertyName))
96+
propertyDetails.Alternatives.Add(propertyName);
97+
}
98+
9399
if (propertyAttribute.ConstructorArguments.Length == 1)
100+
{
94101
foreach (var synonymArg in propertyAttribute.ConstructorArguments[0].Values)
102+
{
95103
if (synonymArg.Value is string synonym)
96-
propertiesByKeyword[synonym.ToUpperInvariant()] = propertyDetails;
104+
{
105+
var synonymName = synonym.ToUpperInvariant();
106+
if (!propertiesByKeyword.ContainsKey(synonymName))
107+
propertyDetails.Alternatives.Add(synonymName);
108+
}
109+
}
110+
}
97111
}
98112

99113
var template = Template.Parse(EmbeddedResource.GetContent("NpgsqlConnectionStringBuilder.snbtxt"), "NpgsqlConnectionStringBuilder.snbtxt");
@@ -115,5 +129,18 @@ sealed class PropertyDetails
115129
public bool IsEnum { get; set; }
116130
public bool IsObsolete { get; set; }
117131
public object? DefaultValue { get; set; }
132+
133+
public HashSet<string> Alternatives { get; } = new(StringComparer.Ordinal);
134+
135+
public PropertyDetails Clone()
136+
=> new()
137+
{
138+
Name = Name,
139+
CanonicalName = CanonicalName,
140+
TypeName = TypeName,
141+
IsEnum = IsEnum,
142+
IsObsolete = IsObsolete,
143+
DefaultValue = DefaultValue
144+
};
118145
}
119-
}
146+
}

‎src/Npgsql/NpgsqlConnectionStringBuilder.cs‎

Lines changed: 33 additions & 23 deletions

0 commit comments

Comments
 (0)