HipcGenerator: return FrozenDictionary<,>.Empty when there are no command implementations, otherwise create FrozenDictionary from a IEnumerable<KeyValuePair<,>> instead of a Dictionary<,>``

This commit is contained in:
Jim Horvath 2024-02-23 00:08:10 -05:00
commit bfb83f0341

View file

@ -116,7 +116,14 @@ namespace Ryujinx.Horizon.Generators.Hipc
private static void GenerateMethodTable(CodeGenerator generator, Compilation compilation, CommandInterface commandInterface)
{
generator.EnterScope($"public IReadOnlyDictionary<int, CommandHandler> GetCommandHandlers()");
generator.EnterScope($"return new Dictionary<int, CommandHandler>()");
if (commandInterface.CommandImplementations.Count == 0)
{
generator.AppendLine("return FrozenDictionary<int, CommandHandler>.Empty;");
}
else
{
generator.EnterScope($"return FrozenDictionary.ToFrozenDictionary(new []");
foreach (var method in commandInterface.CommandImplementations)
{
@ -126,7 +133,7 @@ namespace Ryujinx.Horizon.Generators.Hipc
if (args.Length == 0)
{
generator.AppendLine($"{{ {commandId}, new CommandHandler({method.Identifier.Text}, Array.Empty<CommandArg>()) }},");
generator.AppendLine($"KeyValuePair.Create({commandId}, new CommandHandler({method.Identifier.Text}, Array.Empty<CommandArg>())),");
}
else
{
@ -167,12 +174,14 @@ namespace Ryujinx.Horizon.Generators.Hipc
args[index++] = arg;
}
generator.AppendLine($"{{ {commandId}, new CommandHandler({method.Identifier.Text}, {string.Join(", ", args)}) }},");
generator.AppendLine($"KeyValuePair.Create({commandId}, new CommandHandler({method.Identifier.Text}, {string.Join(", ", args)})),");
}
}
}
generator.LeaveScope(".ToFrozenDictionary();");
generator.LeaveScope(");");
}
generator.LeaveScope();
}