mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2026-03-11 17:45:43 +00:00
Optimize IpcCommand source gen
This commit is contained in:
parent
73406d1f3a
commit
b9da6a15d7
1 changed files with 54 additions and 6 deletions
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Immutable;
|
||||
using System.Threading;
|
||||
|
|
@ -9,20 +10,60 @@ namespace Ryujinx.HLE.Generators
|
|||
[Generator]
|
||||
public class IpcCommandGenerator : IIncrementalGenerator
|
||||
{
|
||||
private sealed class CommandData
|
||||
private sealed class CommandData : IEquatable<CommandData>
|
||||
{
|
||||
public required string Namespace { get; init; }
|
||||
public required string TypeName { get; init; }
|
||||
public required string MethodName { get; init; }
|
||||
public required ImmutableArray<int> CommandIds { get; init; }
|
||||
|
||||
public bool Equals(CommandData other)
|
||||
{
|
||||
return Namespace == other.Namespace && TypeName == other.TypeName && MethodName == other.MethodName && CommandIds.SequenceEqual(other.CommandIds);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
=> obj is CommandData other && Equals(other);
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
var hashCode = (Namespace != null ? Namespace.GetHashCode() : 0);
|
||||
hashCode = (hashCode * 397) ^ (TypeName != null ? TypeName.GetHashCode() : 0);
|
||||
hashCode = (hashCode * 397) ^ (MethodName != null ? MethodName.GetHashCode() : 0);
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class ServiceData
|
||||
private sealed class ServiceData : IEquatable<ServiceData>
|
||||
{
|
||||
public required string Namespace { get; init; }
|
||||
public required string TypeName { get; init; }
|
||||
public required ImmutableArray<CommandData> CmifCommands { get; init; }
|
||||
public required ImmutableArray<CommandData> TipcCommands { get; init; }
|
||||
|
||||
|
||||
public bool Equals(ServiceData other)
|
||||
{
|
||||
return Namespace == other.Namespace && TypeName == other.TypeName && CmifCommands.SequenceEqual(other.CmifCommands) && TipcCommands.SequenceEqual(other.TipcCommands);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is ServiceData other && Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
var hashCode = (Namespace != null ? Namespace.GetHashCode() : 0);
|
||||
hashCode = (hashCode * 397) ^ (TypeName != null ? TypeName.GetHashCode() : 0);
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialize(IncrementalGeneratorInitializationContext context)
|
||||
|
|
@ -82,10 +123,17 @@ namespace Ryujinx.HLE.Generators
|
|||
|
||||
generator.EnterScope($"namespace {data.Namespace}");
|
||||
generator.EnterScope($"partial class {data.TypeName}");
|
||||
|
||||
GenerateCommandMethod("Cmif", data.CmifCommands);
|
||||
GenerateCommandMethod("Tipc", data.TipcCommands);
|
||||
|
||||
|
||||
if (!data.CmifCommands.IsEmpty)
|
||||
{
|
||||
GenerateCommandMethod("Cmif", data.CmifCommands);
|
||||
}
|
||||
|
||||
if (!data.TipcCommands.IsEmpty)
|
||||
{
|
||||
GenerateCommandMethod("Tipc", data.TipcCommands);
|
||||
}
|
||||
|
||||
generator.LeaveScope();
|
||||
generator.LeaveScope();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue