mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[Refactor] Use static lambdas in LINQ queries for improved performance
This commit is contained in:
@@ -43,7 +43,7 @@ public class PluginRegisterGenerator : ISourceGenerator
|
||||
public void Initialize(GeneratorInitializationContext context) =>
|
||||
|
||||
// Nothing to do
|
||||
context.RegisterForSyntaxNotifications(() => new PluginFinder());
|
||||
context.RegisterForSyntaxNotifications(static () => new PluginFinder());
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Execute(GeneratorExecutionContext context)
|
||||
@@ -62,11 +62,11 @@ public class PluginRegisterGenerator : ISourceGenerator
|
||||
if(pluginRegister == null) return;
|
||||
|
||||
var @namespace =
|
||||
(pluginRegister.Ancestors().FirstOrDefault(x => x is FileScopedNamespaceDeclarationSyntax) as
|
||||
(pluginRegister.Ancestors().FirstOrDefault(static x => x is FileScopedNamespaceDeclarationSyntax) as
|
||||
FileScopedNamespaceDeclarationSyntax)?.Name.ToString();
|
||||
|
||||
@namespace ??=
|
||||
(pluginRegister.Ancestors().FirstOrDefault(x => x is NamespaceDeclarationSyntax) as
|
||||
(pluginRegister.Ancestors().FirstOrDefault(static x => x is NamespaceDeclarationSyntax) as
|
||||
NamespaceDeclarationSyntax)?.ToString();
|
||||
|
||||
string className = pluginRegister.Identifier.Text;
|
||||
@@ -357,114 +357,127 @@ public class PluginRegisterGenerator : ISourceGenerator
|
||||
{
|
||||
if(syntaxNode is not ClassDeclarationSyntax plugin) return;
|
||||
|
||||
if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier
|
||||
.ValueText ==
|
||||
"IPluginRegister") ==
|
||||
if(plugin.BaseList?.Types.Any(static t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)
|
||||
?.Identifier.ValueText ==
|
||||
"IPluginRegister") ==
|
||||
true)
|
||||
Register = plugin;
|
||||
|
||||
if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier
|
||||
.ValueText ==
|
||||
"IArchive") ==
|
||||
if(plugin.BaseList?.Types.Any(static t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)
|
||||
?.Identifier.ValueText ==
|
||||
"IArchive") ==
|
||||
true)
|
||||
if(!Archives.Contains(plugin.Identifier.Text))
|
||||
Archives.Add(plugin.Identifier.Text);
|
||||
{
|
||||
if(!Archives.Contains(plugin.Identifier.Text)) Archives.Add(plugin.Identifier.Text);
|
||||
}
|
||||
|
||||
if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier
|
||||
.ValueText ==
|
||||
"IChecksum") ==
|
||||
if(plugin.BaseList?.Types.Any(static t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)
|
||||
?.Identifier.ValueText ==
|
||||
"IChecksum") ==
|
||||
true)
|
||||
if(!Checksums.Contains(plugin.Identifier.Text))
|
||||
Checksums.Add(plugin.Identifier.Text);
|
||||
{
|
||||
if(!Checksums.Contains(plugin.Identifier.Text)) Checksums.Add(plugin.Identifier.Text);
|
||||
}
|
||||
|
||||
if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier
|
||||
.ValueText ==
|
||||
"IFilesystem") ==
|
||||
if(plugin.BaseList?.Types.Any(static t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)
|
||||
?.Identifier.ValueText ==
|
||||
"IFilesystem") ==
|
||||
true)
|
||||
if(!FileSystems.Contains(plugin.Identifier.Text))
|
||||
FileSystems.Add(plugin.Identifier.Text);
|
||||
{
|
||||
if(!FileSystems.Contains(plugin.Identifier.Text)) FileSystems.Add(plugin.Identifier.Text);
|
||||
}
|
||||
|
||||
if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier
|
||||
.ValueText ==
|
||||
"IFilter") ==
|
||||
if(plugin.BaseList?.Types.Any(static t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)
|
||||
?.Identifier.ValueText ==
|
||||
"IFilter") ==
|
||||
true)
|
||||
if(!Filters.Contains(plugin.Identifier.Text))
|
||||
Filters.Add(plugin.Identifier.Text);
|
||||
{
|
||||
if(!Filters.Contains(plugin.Identifier.Text)) Filters.Add(plugin.Identifier.Text);
|
||||
}
|
||||
|
||||
if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier
|
||||
.ValueText ==
|
||||
"IFloppyImage") ==
|
||||
if(plugin.BaseList?.Types.Any(static t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)
|
||||
?.Identifier.ValueText ==
|
||||
"IFloppyImage") ==
|
||||
true)
|
||||
if(!FloppyImagePlugins.Contains(plugin.Identifier.Text))
|
||||
FloppyImagePlugins.Add(plugin.Identifier.Text);
|
||||
{
|
||||
if(!FloppyImagePlugins.Contains(plugin.Identifier.Text)) FloppyImagePlugins.Add(plugin.Identifier.Text);
|
||||
}
|
||||
|
||||
if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier
|
||||
.ValueText ==
|
||||
"IFluxImage") ==
|
||||
if(plugin.BaseList?.Types.Any(static t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)
|
||||
?.Identifier.ValueText ==
|
||||
"IFluxImage") ==
|
||||
true)
|
||||
if(!FluxImagePlugins.Contains(plugin.Identifier.Text))
|
||||
FluxImagePlugins.Add(plugin.Identifier.Text);
|
||||
{
|
||||
if(!FluxImagePlugins.Contains(plugin.Identifier.Text)) FluxImagePlugins.Add(plugin.Identifier.Text);
|
||||
}
|
||||
|
||||
|
||||
if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier
|
||||
.ValueText is "IMediaImage"
|
||||
or "IOpticalMediaImage"
|
||||
or "IFloppyImage"
|
||||
or "ITapeImage"
|
||||
or "IFluxImage") ==
|
||||
if(plugin.BaseList?.Types.Any(static t =>
|
||||
((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier
|
||||
.ValueText is "IMediaImage"
|
||||
or "IOpticalMediaImage"
|
||||
or "IFloppyImage"
|
||||
or "ITapeImage"
|
||||
or "IFluxImage") ==
|
||||
true)
|
||||
if(!MediaImagePlugins.Contains(plugin.Identifier.Text))
|
||||
MediaImagePlugins.Add(plugin.Identifier.Text);
|
||||
{
|
||||
if(!MediaImagePlugins.Contains(plugin.Identifier.Text)) MediaImagePlugins.Add(plugin.Identifier.Text);
|
||||
}
|
||||
|
||||
if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier
|
||||
.ValueText ==
|
||||
"IPartition") ==
|
||||
if(plugin.BaseList?.Types.Any(static t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)
|
||||
?.Identifier.ValueText ==
|
||||
"IPartition") ==
|
||||
true)
|
||||
if(!PartitionPlugins.Contains(plugin.Identifier.Text))
|
||||
PartitionPlugins.Add(plugin.Identifier.Text);
|
||||
{
|
||||
if(!PartitionPlugins.Contains(plugin.Identifier.Text)) PartitionPlugins.Add(plugin.Identifier.Text);
|
||||
}
|
||||
|
||||
if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier
|
||||
.ValueText ==
|
||||
"IReadOnlyFilesystem") ==
|
||||
if(plugin.BaseList?.Types.Any(static t =>
|
||||
((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier
|
||||
.ValueText ==
|
||||
"IReadOnlyFilesystem") ==
|
||||
true)
|
||||
{
|
||||
if(!ReadOnlyFileSystems.Contains(plugin.Identifier.Text))
|
||||
ReadOnlyFileSystems.Add(plugin.Identifier.Text);
|
||||
}
|
||||
|
||||
if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier
|
||||
.ValueText ==
|
||||
"IWritableFloppyImage") ==
|
||||
if(plugin.BaseList?.Types.Any(static t =>
|
||||
((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier
|
||||
.ValueText ==
|
||||
"IWritableFloppyImage") ==
|
||||
true)
|
||||
{
|
||||
if(!WritableFloppyImagePlugins.Contains(plugin.Identifier.Text))
|
||||
WritableFloppyImagePlugins.Add(plugin.Identifier.Text);
|
||||
}
|
||||
|
||||
if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier
|
||||
.ValueText ==
|
||||
"IWritableFluxImage") ==
|
||||
if(plugin.BaseList?.Types.Any(static t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)
|
||||
?.Identifier.ValueText ==
|
||||
"IWritableFluxImage") ==
|
||||
true)
|
||||
{
|
||||
if(!WritableFluxImagePlugins.Contains(plugin.Identifier.Text))
|
||||
WritableFluxImagePlugins.Add(plugin.Identifier.Text);
|
||||
}
|
||||
|
||||
if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier
|
||||
.ValueText is "IWritableImage"
|
||||
or "IWritableOpticalImage"
|
||||
or "IWritableTapeImage"
|
||||
or "IByteAddressableImage"
|
||||
or "IWritableFluxImage") ==
|
||||
if(plugin.BaseList?.Types.Any(static t =>
|
||||
((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier
|
||||
.ValueText is "IWritableImage"
|
||||
or "IWritableOpticalImage"
|
||||
or "IWritableTapeImage"
|
||||
or "IByteAddressableImage"
|
||||
or "IWritableFluxImage") ==
|
||||
true)
|
||||
{
|
||||
if(!WritableImagePlugins.Contains(plugin.Identifier.Text))
|
||||
WritableImagePlugins.Add(plugin.Identifier.Text);
|
||||
}
|
||||
|
||||
if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier
|
||||
.ValueText ==
|
||||
"IByteAddressableImage") ==
|
||||
if(plugin.BaseList?.Types.Any(static t =>
|
||||
((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier
|
||||
.ValueText ==
|
||||
"IByteAddressableImage") ==
|
||||
true)
|
||||
{
|
||||
if(!ByteAddressableImagePlugins.Contains(plugin.Identifier.Text))
|
||||
|
||||
@@ -108,7 +108,7 @@ public class SwapEndianGenerator : IIncrementalGenerator
|
||||
|
||||
// Create unique file name by including containing types
|
||||
string fileName = containingTypes.Count > 0
|
||||
? $"{string.Join("_", containingTypes.Select(t => t.Name))}_{structName}_SwapEndian.g.cs"
|
||||
? $"{string.Join("_", containingTypes.Select(static t => t.Name))}_{structName}_SwapEndian.g.cs"
|
||||
: $"{structName}_SwapEndian.g.cs";
|
||||
|
||||
context.AddSource(fileName, SourceText.From(generatedSource, Encoding.UTF8));
|
||||
@@ -361,8 +361,7 @@ public class SwapEndianGenerator : IIncrementalGenerator
|
||||
"byte" or "Byte" or "sbyte" or "SByte" =>
|
||||
$" // {fieldName} - no swap needed for byte types",
|
||||
|
||||
"string" or "String" =>
|
||||
$" // {fieldName} - no swap needed for string types",
|
||||
"string" or "String" => $" // {fieldName} - no swap needed for string types",
|
||||
|
||||
"Guid" => $" // TODO: Implement GUID swap for {fieldName}",
|
||||
|
||||
@@ -442,7 +441,7 @@ public class SwapEndianGenerator : IIncrementalGenerator
|
||||
// Fallback to assuming it's a nested struct
|
||||
}
|
||||
|
||||
private static (string code, bool usesEnumHelper) HandleStructOrEnumArray(string fieldName, string elementType,
|
||||
private static (string code, bool usesEnumHelper) HandleStructOrEnumArray(string fieldName, string elementType,
|
||||
ITypeSymbol typeSymbol)
|
||||
{
|
||||
// Check if we have semantic information about the array type
|
||||
@@ -614,5 +613,4 @@ public class SwapEndianGenerator : IIncrementalGenerator
|
||||
return value;
|
||||
}
|
||||
""";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -106,7 +106,7 @@ public class SwapPdpEndianGenerator : IIncrementalGenerator
|
||||
|
||||
// Create unique file name by including containing types
|
||||
string fileName = containingTypes.Count > 0
|
||||
? $"{string.Join("_", containingTypes.Select(t => t.Name))}_{structName}_SwapPdpEndian.g.cs"
|
||||
? $"{string.Join("_", containingTypes.Select(static t => t.Name))}_{structName}_SwapPdpEndian.g.cs"
|
||||
: $"{structName}_SwapPdpEndian.g.cs";
|
||||
|
||||
context.AddSource(fileName, SourceText.From(generatedSource, Encoding.UTF8));
|
||||
|
||||
Reference in New Issue
Block a user