Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions Sources/Falko.Foundry.CSharp/Compilers/TypeElementCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ internal sealed class TypeElementCompiler : IElementCompiler<TypeElement>
{
private const int MinimumTypeLength = 64; // average type name length

private static readonly int LeftRightAngleBracketsLength
= CSharpLanguageConstants.LeftAngleBracket.Length + CSharpLanguageConstants.RightAngleBracket.Length;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Compile
(
Expand All @@ -36,8 +39,6 @@ scoped in TypeElement element
var genericTypes = element.GenericTypes;
StructArgumentException.ThrowIfDefault(genericTypes, nameof(element.GenericTypes));

var leftAngleBracket = CSharpLanguageConstants.LeftAngleBracket;
var rightAngleBracket = CSharpLanguageConstants.RightAngleBracket;
var dot = CSharpLanguageConstants.Dot;
var commaSpace = CSharpLanguageConstants.CommaSpace;

Expand All @@ -47,10 +48,12 @@ scoped in TypeElement element
var typeLength = typeNamespace.Length + typeName.Length + dotBetweenLength;
var genericTypesCount = genericTypes.Length;

if (genericTypesCount is not 0)
var hasGenericTypes = genericTypesCount is not 0;

if (hasGenericTypes)
{
typeLength += leftAngleBracket.Length + rightAngleBracket.Length; // for generic type brackets
typeLength += checked(MinimumTypeLength * genericTypesCount); // for do fewer allocations when appending generic types
typeLength += LeftRightAngleBracketsLength; // for generic type brackets
typeLength += MinimumTypeLength * genericTypesCount; // for do fewer allocations when appending generic types
typeLength += commaSpace.Length * (genericTypesCount - 1); // for comma and space between generic types
Comment thread
fembina marked this conversation as resolved.
}

Expand All @@ -64,9 +67,9 @@ scoped in TypeElement element

buffer.Append(typeName);

if (genericTypesCount is 0) return;
if (hasGenericTypes is false) return;

buffer.Append(leftAngleBracket);
buffer.Append(CSharpLanguageConstants.LeftAngleBracket);

var genericTypesSpan = genericTypes.AsSpan();
var genericTypeIndex = 0;
Expand All @@ -85,6 +88,6 @@ scoped in TypeElement element
goto genericTypeAppendLoop;
}

buffer.Append(rightAngleBracket);
buffer.Append(CSharpLanguageConstants.RightAngleBracket);
}
}
Loading