Skip to content

Commit 64613a1

Browse files
Remove AI Slop
1 parent 5ff8feb commit 64613a1

File tree

1 file changed

+21
-33
lines changed

1 file changed

+21
-33
lines changed

src/CommunityToolkit.Maui.SourceGenerators.Internal/Generators/AttachedBindablePropertyAttributeSourceGenerator.cs

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class AttachedBindablePropertyAttributeSourceGenerator : IIncrementalGene
2121

2222
const string bindablePropertyFullName = "global::Microsoft.Maui.Controls.BindableProperty";
2323
const string bindableObjectFullName = "global::Microsoft.Maui.Controls.BindableObject";
24+
2425
const string attachedBindablePropertyAttributeSource =
2526
/* language=C#-test */
2627
//lang=csharp
@@ -140,57 +141,42 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
140141

141142
static void ExecuteAllValues(SourceProductionContext context, ImmutableArray<AttachedBindablePropertySemanticValues> semanticValues)
142143
{
143-
// Pre-allocate dictionary with expected capacity
144-
var groupedValues = new Dictionary<(string, string, string, string), List<AttachedBindablePropertySemanticValues>>(semanticValues.Length);
145-
146-
// Single-pass grouping without LINQ
147-
foreach (var sv in semanticValues)
148-
{
149-
var key = (sv.ClassInformation.ClassName, sv.ClassInformation.ContainingNamespace, sv.ClassInformation.ContainingTypes, sv.ClassInformation.GenericTypeParameters);
150-
151-
if (!groupedValues.TryGetValue(key, out var list))
152-
{
153-
list = [];
154-
groupedValues[key] = list;
155-
}
156-
list.Add(sv);
157-
}
158-
159144
// Use ArrayPool for temporary storage
160145
var attachedBindablePropertiesBuffer = System.Buffers.ArrayPool<AttachedBindablePropertyModel>.Shared.Rent(32);
161146

162147
try
163148
{
164-
foreach (var keyValuePair in groupedValues)
149+
foreach (var attachedBindablePropertySemanticValues in semanticValues)
165150
{
166-
var (className, containingNamespace, containingTypes, genericTypeParameters) = keyValuePair.Key;
167-
var values = keyValuePair.Value;
151+
var className = attachedBindablePropertySemanticValues.ClassInformation.ClassName;
152+
var containingNamespace = attachedBindablePropertySemanticValues.ClassInformation.ContainingNamespace;
153+
var containingTypes = attachedBindablePropertySemanticValues.ClassInformation.ContainingTypes;
154+
var genericTypeParameters = attachedBindablePropertySemanticValues.ClassInformation.GenericTypeParameters;
168155

169-
if (values.Count is 0 || string.IsNullOrEmpty(className) || string.IsNullOrEmpty(containingNamespace))
156+
if (string.IsNullOrEmpty(className) || string.IsNullOrEmpty(containingNamespace))
170157
{
171158
continue;
172159
}
173160

174161
// Flatten attached bindable properties without SelectMany allocation
175162
var attachedBindablePropertiesCount = 0;
176-
foreach (var value in values)
163+
164+
foreach (var abp in attachedBindablePropertySemanticValues.BindableProperties.AsImmutableArray())
177165
{
178-
foreach (var abp in value.BindableProperties.AsImmutableArray())
166+
if (attachedBindablePropertiesCount >= attachedBindablePropertiesBuffer.Length)
179167
{
180-
if (attachedBindablePropertiesCount >= attachedBindablePropertiesBuffer.Length)
181-
{
182-
var newBuffer = System.Buffers.ArrayPool<AttachedBindablePropertyModel>.Shared.Rent(attachedBindablePropertiesBuffer.Length * 2);
183-
Array.Copy(attachedBindablePropertiesBuffer, newBuffer, attachedBindablePropertiesBuffer.Length);
184-
System.Buffers.ArrayPool<AttachedBindablePropertyModel>.Shared.Return(attachedBindablePropertiesBuffer);
185-
attachedBindablePropertiesBuffer = newBuffer;
186-
}
187-
attachedBindablePropertiesBuffer[attachedBindablePropertiesCount++] = abp;
168+
var newBuffer = System.Buffers.ArrayPool<AttachedBindablePropertyModel>.Shared.Rent(attachedBindablePropertiesBuffer.Length * 2);
169+
Array.Copy(attachedBindablePropertiesBuffer, newBuffer, attachedBindablePropertiesBuffer.Length);
170+
System.Buffers.ArrayPool<AttachedBindablePropertyModel>.Shared.Return(attachedBindablePropertiesBuffer);
171+
attachedBindablePropertiesBuffer = newBuffer;
188172
}
173+
174+
attachedBindablePropertiesBuffer[attachedBindablePropertiesCount++] = abp;
189175
}
190176

191177
var attachedBindableProperties = ImmutableArray.Create(attachedBindablePropertiesBuffer, 0, attachedBindablePropertiesCount);
192178

193-
var classAccessibility = values[0].ClassInformation.DeclaredAccessibility;
179+
var classAccessibility = attachedBindablePropertySemanticValues.ClassInformation.DeclaredAccessibility;
194180

195181
var combinedClassInfo = new ClassInformation(className, classAccessibility, containingNamespace, containingTypes, genericTypeParameters);
196182
var combinedValues = new AttachedBindablePropertySemanticValues(combinedClassInfo, attachedBindableProperties.AsEquatableArray());
@@ -331,7 +317,6 @@ static void GenerateAttachedBindableProperty(StringBuilder sb, in AttachedBindab
331317
// Generate Get method
332318
if (info.GetterAccessibility is not null)
333319
{
334-
335320
if (info.GetterMethodXMLDocumentation is not null)
336321
{
337322
sb.Append(info.GetterMethodXMLDocumentation)
@@ -476,7 +461,7 @@ static AttachedBindablePropertyModel CreateAttachedBindablePropertyModel(Attribu
476461
var getterAccessibility = GetAccessibilityString(attributeData, "GetterAccessibility");
477462
var setterAccessibility = GetAccessibilityString(attributeData, "SetterAccessibility");
478463
var bindablePropertyAccessibility = GetAccessibilityString(attributeData, "BindablePropertyAccessibility")
479-
?? throw new InvalidOperationException("Bindable Property Accessibilty Cannot be null");
464+
?? throw new InvalidOperationException("Bindable Property Accessibilty Cannot be null");
480465

481466
var getterMethodXMLDocumentation = GetXMLDocumenation(attributeData, "GetterMethodXmlDocumentation");
482467
var setterMethodXMLDocumentation = GetXMLDocumenation(attributeData, "SetterMethodXmlDocumentation");
@@ -502,6 +487,7 @@ static AttachedBindablePropertyModel CreateAttachedBindablePropertyModel(Attribu
502487
setterMethodXMLDocumentation
503488
);
504489
}
490+
505491
// DefaultValue can only be a primitive type, enum, typeof expression or array
506492
// In C#, attribute arguments are limited to compile-time constants, typeof expressions, and single-dimensional arrays
507493
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -631,6 +617,7 @@ static string GetContainingTypes(INamedTypeSymbol typeSymbol)
631617
{
632618
sb.Append('.');
633619
}
620+
634621
sb.Append(stack.Pop());
635622
first = false;
636623
}
@@ -659,6 +646,7 @@ static string GetGenericTypeParameters(INamedTypeSymbol typeSymbol)
659646
{
660647
sb.Append(", ");
661648
}
649+
662650
sb.Append(typeParams[i].Name);
663651
}
664652

0 commit comments

Comments
 (0)