Skip to content

Commit 1764049

Browse files
committed
Use Array
1 parent eb56e5a commit 1764049

File tree

6 files changed

+17
-19
lines changed

6 files changed

+17
-19
lines changed

src/DynamoDBGenerator.SourceGenerator/Extensions/TypeExtensions.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ or SpecialType.System_Double
215215
or SpecialType.System_Single;
216216
}
217217

218-
public static ImmutableArray<DynamoDbDataMember> GetDynamoDbProperties(this ITypeSymbol symbol)
218+
public static DynamoDbDataMember[] GetDynamoDbProperties(this ITypeSymbol symbol)
219219
{
220220
// A special rule when it comes to Tuples.
221221
// If we remove this we will get duplicated DataMembers when tuples are being used.
@@ -238,9 +238,7 @@ public static ImmutableArray<DynamoDbDataMember> GetDynamoDbProperties(this ITyp
238238
.Where(x => x is not null)
239239
.Select(x => x!.Value);
240240

241-
var builder = ImmutableArray.CreateBuilder<DynamoDbDataMember>();
242-
builder.AddRange(items);
243-
return builder.ToImmutableArray();
241+
return items.ToArray();
244242

245243
static DynamoDbDataMember? Create(DataMember dataMember)
246244
{

src/DynamoDBGenerator.SourceGenerator/Generations/AttributeExpressionName.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static class AttributeExpressionName
1313
private const string SetFieldName = "___set___";
1414

1515
private static readonly Func<ITypeSymbol, string> TypeName = TypeExtensions.SuffixedTypeSymbolNameFactory("Names", SymbolEqualityComparer.Default);
16-
internal static IEnumerable<string> CreateClasses(IEnumerable<DynamoDBMarshallerArguments> arguments, Func<ITypeSymbol, ImmutableArray<DynamoDbDataMember>> getDynamoDbProperties, MarshallerOptions options)
16+
internal static IEnumerable<string> CreateClasses(IEnumerable<DynamoDBMarshallerArguments> arguments, Func<ITypeSymbol, DynamoDbDataMember[]> getDynamoDbProperties, MarshallerOptions options)
1717
{
1818
// Using _comparer can double classes when there's a None nullable property mixed with a nullable property
1919
var hashSet = new HashSet<ITypeSymbol>(SymbolEqualityComparer.Default);
@@ -86,7 +86,7 @@ private static IEnumerable<string> YieldSelector((bool IsUnknown, DynamoDbDataMe
8686
}
8787
}
8888

89-
private static CodeFactory CreateStruct(ITypeSymbol typeSymbol, Func<ITypeSymbol, ImmutableArray<DynamoDbDataMember>> fn, MarshallerOptions options)
89+
private static CodeFactory CreateStruct(ITypeSymbol typeSymbol, Func<ITypeSymbol, DynamoDbDataMember[]> fn, MarshallerOptions options)
9090
{
9191
var dataMembers = fn(typeSymbol)
9292
.Select(x => (

src/DynamoDBGenerator.SourceGenerator/Generations/AttributeExpressionValue.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ private static IEnumerable<string> YieldSelector((bool IsUnknown, DynamoDbDataMe
8282
return $"if ({x.DDB.DataMember.NameAsPrivateField}.IsValueCreated)".CreateScope(x.DDB.DataMember.Type.NotNullIfStatement(accessPattern, $"yield return new ({x.DDB.DataMember.NameAsPrivateField}.Value, {Marshaller.InvokeMarshallerMethod(x.DDB.DataMember.Type, $"entity.{x.DDB.DataMember.Name}", $"\"{x.DDB.DataMember.Name}\"", options, MarshallerOptions.FieldReference)} ?? {AttributeValueUtilityFactory.Null});"));
8383

8484
}
85-
internal static IEnumerable<string> CreateExpressionAttributeValue(IEnumerable<DynamoDBMarshallerArguments> arguments, Func<ITypeSymbol, ImmutableArray<DynamoDbDataMember>> getDynamoDbProperties, MarshallerOptions options)
85+
internal static IEnumerable<string> CreateExpressionAttributeValue(IEnumerable<DynamoDBMarshallerArguments> arguments, Func<ITypeSymbol, DynamoDbDataMember[]> getDynamoDbProperties, MarshallerOptions options)
8686
{
8787
// Using _comparer can double classes when there's a None nullable property mixed with a nullable property
8888
var hashSet = new HashSet<ITypeSymbol>(SymbolEqualityComparer.Default);
8989

9090
return arguments
9191
.SelectMany(x => CodeFactory.Create(x.ArgumentType, y => CreateStruct(y, getDynamoDbProperties, options), hashSet));
9292
}
93-
private static CodeFactory CreateStruct(ITypeSymbol typeSymbol, Func<ITypeSymbol, ImmutableArray<DynamoDbDataMember>> fn, MarshallerOptions options)
93+
private static CodeFactory CreateStruct(ITypeSymbol typeSymbol, Func<ITypeSymbol, DynamoDbDataMember[]> fn, MarshallerOptions options)
9494
{
9595
var dataMembers =
9696
options.IsConvertable(typeSymbol)

src/DynamoDBGenerator.SourceGenerator/Generations/KeyMarshaller.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private static IEnumerable<string> CreateAssignment(string validateReference, st
2727
return $"if ({validateReference})".CreateScope(innerContent);
2828

2929
}
30-
private static IEnumerable<string> MethodBody(ITypeSymbol typeSymbol, Func<ITypeSymbol, ImmutableArray<DynamoDbDataMember>> fn, MarshallerOptions options)
30+
private static IEnumerable<string> MethodBody(ITypeSymbol typeSymbol, Func<ITypeSymbol, DynamoDbDataMember[]> fn, MarshallerOptions options)
3131
{
3232
var keyStructure = DynamoDbDataMember.GetKeyStructure(fn(typeSymbol));
3333
if (keyStructure is null)
@@ -57,7 +57,7 @@ private static IEnumerable<string> MethodBody(ITypeSymbol typeSymbol, Func<IType
5757
yield return s;
5858

5959
}
60-
internal static IEnumerable<string> CreateKeys(IEnumerable<DynamoDBMarshallerArguments> arguments, Func<ITypeSymbol, ImmutableArray<DynamoDbDataMember>> getDynamoDbProperties, MarshallerOptions options)
60+
internal static IEnumerable<string> CreateKeys(IEnumerable<DynamoDBMarshallerArguments> arguments, Func<ITypeSymbol, DynamoDbDataMember[]> getDynamoDbProperties, MarshallerOptions options)
6161
{
6262
var hashSet = new HashSet<ITypeSymbol>(SymbolEqualityComparer.IncludeNullability);
6363

@@ -111,7 +111,7 @@ internal static string AssignmentRoot(ITypeSymbol typeSymbol)
111111
return
112112
$"new {KeyMarshallerImplementationTypeName}((pk, rk, ipk, irk, dm) => {MethodName(typeSymbol)}({MarshallerOptions.FieldReference}, pk, rk, ipk, irk, dm))";
113113
}
114-
private static CodeFactory StaticAttributeValueDictionaryKeys(ITypeSymbol typeSymbol, Func<ITypeSymbol, ImmutableArray<DynamoDbDataMember>> fn, MarshallerOptions options)
114+
private static CodeFactory StaticAttributeValueDictionaryKeys(ITypeSymbol typeSymbol, Func<ITypeSymbol, DynamoDbDataMember[]> fn, MarshallerOptions options)
115115
{
116116

117117
var code = $"private static Dictionary<string, AttributeValue> {MethodName(typeSymbol)}({MarshallerOptions.Name} {MarshallerOptions.ParamReference}, object? {PkReference}, object? {RkReference}, bool {EnforcePkReference}, bool {EnforceRkReference}, string? index = null)"

src/DynamoDBGenerator.SourceGenerator/Generations/Marshaller.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public static class Marshaller
1313
private static readonly Func<ITypeSymbol, string> GetSerializationMethodName = TypeExtensions.SuffixedTypeSymbolNameFactory("_M", SymbolEqualityComparer.IncludeNullability);
1414
private const string ParamReference = "entity";
1515

16-
internal static IEnumerable<string> CreateClass(IEnumerable<DynamoDBMarshallerArguments> arguments, Func<ITypeSymbol, ImmutableArray<DynamoDbDataMember>> getDynamoDbProperties, MarshallerOptions options)
16+
internal static IEnumerable<string> CreateClass(IEnumerable<DynamoDBMarshallerArguments> arguments, Func<ITypeSymbol, DynamoDbDataMember[]> getDynamoDbProperties, MarshallerOptions options)
1717
{
1818
return $"private static class {ClassName}".CreateScope(TypeContent(arguments, getDynamoDbProperties, options));
1919
}
20-
private static CodeFactory CreateDictionaryMethod(ITypeSymbol typeSymbol, Func<ITypeSymbol, ImmutableArray<DynamoDbDataMember>> fn, MarshallerOptions options)
20+
private static CodeFactory CreateDictionaryMethod(ITypeSymbol typeSymbol, Func<ITypeSymbol, DynamoDbDataMember[]> fn, MarshallerOptions options)
2121
{
2222
var properties = fn(typeSymbol)
2323
.Select(x =>
@@ -59,7 +59,7 @@ private static CodeFactory CreateDictionaryMethod(ITypeSymbol typeSymbol, Func<I
5959

6060
}
6161

62-
private static IEnumerable<string> TypeContent(IEnumerable<DynamoDBMarshallerArguments> arguments, Func<ITypeSymbol, ImmutableArray<DynamoDbDataMember>> getDynamoDbProperties, MarshallerOptions options)
62+
private static IEnumerable<string> TypeContent(IEnumerable<DynamoDBMarshallerArguments> arguments, Func<ITypeSymbol, DynamoDbDataMember[]> getDynamoDbProperties, MarshallerOptions options)
6363
{
6464
var hashset = new HashSet<ITypeSymbol>(SymbolEqualityComparer.IncludeNullability);
6565

@@ -72,7 +72,7 @@ private static IEnumerable<string> TypeContent(IEnumerable<DynamoDBMarshallerArg
7272
.Concat(CodeFactory.Create(x.ArgumentType, y => CreateMethod(y, getDynamoDbProperties, options), hashset))
7373
);
7474
}
75-
private static CodeFactory CreateMethod(ITypeSymbol type, Func<ITypeSymbol, ImmutableArray<DynamoDbDataMember>> fn, MarshallerOptions options)
75+
private static CodeFactory CreateMethod(ITypeSymbol type, Func<ITypeSymbol, DynamoDbDataMember[]> fn, MarshallerOptions options)
7676
{
7777
if (options.TryWriteConversion(type, ParamReference) is {} conversion)
7878
{

src/DynamoDBGenerator.SourceGenerator/Generations/UnMarshaller.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ public static class UnMarshaller
4444

4545
}
4646
internal static IEnumerable<string> CreateClass(IEnumerable<DynamoDBMarshallerArguments> arguments,
47-
Func<ITypeSymbol, ImmutableArray<DynamoDbDataMember>> getDynamoDbProperties, MarshallerOptions options)
47+
Func<ITypeSymbol, DynamoDbDataMember[]> getDynamoDbProperties, MarshallerOptions options)
4848
{
4949
return $"private static class {UnMarshallerClass}".CreateScope(CreateTypeContents(arguments, getDynamoDbProperties, options));
5050
}
51-
private static CodeFactory CreateCode(ITypeSymbol type, Func<ITypeSymbol, ImmutableArray<DynamoDbDataMember>> fn, MarshallerOptions options)
51+
private static CodeFactory CreateCode(ITypeSymbol type, Func<ITypeSymbol, DynamoDbDataMember[]> fn, MarshallerOptions options)
5252
{
5353
var assignments = fn(type)
5454
.Select(x => (DDB: x, MethodCall: InvokeUnmarshallMethod(x.DataMember.Type, $"{Dict}.GetValueOrDefault(\"{x.AttributeName}\")", $"\"{x.DataMember.Name}\"", options), x.DataMember.Name))
@@ -71,7 +71,7 @@ private static CodeFactory CreateCode(ITypeSymbol type, Func<ITypeSymbol, Immuta
7171
return new CodeFactory(method, assignments.Select(x => x.DDB.DataMember.Type));
7272

7373
}
74-
private static CodeFactory CreateMethod(ITypeSymbol type, Func<ITypeSymbol, ImmutableArray<DynamoDbDataMember>> fn,
74+
private static CodeFactory CreateMethod(ITypeSymbol type, Func<ITypeSymbol, DynamoDbDataMember[]> fn,
7575
MarshallerOptions options)
7676
{
7777

@@ -138,7 +138,7 @@ private static string CreateSignature(ITypeSymbol typeSymbol)
138138
return $"public static {typeSymbol.Representation().annotated} {GetDeserializationMethodName(typeSymbol)}(AttributeValue? {Value}, {MarshallerOptions.Name} {MarshallerOptions.ParamReference}, string? {DataMember} = null)";
139139
}
140140
private static IEnumerable<string> CreateTypeContents(IEnumerable<DynamoDBMarshallerArguments> arguments,
141-
Func<ITypeSymbol, ImmutableArray<DynamoDbDataMember>> getDynamoDbProperties, MarshallerOptions options)
141+
Func<ITypeSymbol, DynamoDbDataMember[]> getDynamoDbProperties, MarshallerOptions options)
142142
{
143143
var hashSet = new HashSet<ITypeSymbol>(SymbolEqualityComparer.IncludeNullability);
144144
return arguments.SelectMany(x =>

0 commit comments

Comments
 (0)