From 7aff19a9824b64fdcd8e6db6fbd1bb11f0c64b22 Mon Sep 17 00:00:00 2001 From: ike709 Date: Sat, 28 Dec 2024 23:09:35 -0600 Subject: [PATCH] Convert some ProcJson classes to structs (#2135) Co-authored-by: ike709 --- DMCompiler/Json/DreamProcJson.cs | 56 +++++++++++++++++--------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/DMCompiler/Json/DreamProcJson.cs b/DMCompiler/Json/DreamProcJson.cs index c7f896a301..070adb86c9 100644 --- a/DMCompiler/Json/DreamProcJson.cs +++ b/DMCompiler/Json/DreamProcJson.cs @@ -3,39 +3,39 @@ namespace DMCompiler.Json; public sealed class ProcDefinitionJson { - public int OwningTypeId { get; set; } - public required string Name { get; set; } - public ProcAttributes Attributes { get; set; } - - public int MaxStackSize { get; set; } - public List? Arguments { get; set; } - public List? Locals { get; set; } - public required List SourceInfo { get; set; } - public byte[]? Bytecode { get; set; } - - public bool IsVerb { get; set; } - public VerbSrc? VerbSrc { get; set; } - public string? VerbName { get; set; } - public string? VerbCategory { get; set; } - public string? VerbDesc { get; set; } - public sbyte Invisibility { get; set; } + public int OwningTypeId { get; init; } + public required string Name { get; init; } + public ProcAttributes Attributes { get; init; } + + public int MaxStackSize { get; init; } + public List? Arguments { get; init; } + public List? Locals { get; init; } + public required List SourceInfo { get; init; } + public byte[]? Bytecode { get; init; } + + public bool IsVerb { get; init; } + public VerbSrc? VerbSrc { get; init; } + public string? VerbName { get; init; } + public string? VerbCategory { get; init; } + public string? VerbDesc { get; init; } + public sbyte Invisibility { get; init; } } -public sealed class ProcArgumentJson { - public required string Name { get; set; } - public DMValueType Type { get; set; } +public struct ProcArgumentJson { + public required string Name { get; init; } + public DMValueType Type { get; init; } } -public sealed class LocalVariableJson { - public int Offset { get; set; } - public int? Remove { get; set; } - public string? Add { get; set; } +public struct LocalVariableJson { + public int Offset { get; init; } + public int? Remove { get; init; } + public string? Add { get; init; } } -public sealed class SourceInfoJson { - public int Offset { get; set; } +public struct SourceInfoJson { + public int Offset { get; init; } public int? File { get; set; } - public int Line { get; set; } + public int Line { get; init; } } public class LineComparer : IEqualityComparer { @@ -43,6 +43,10 @@ public bool Equals(SourceInfoJson? x, SourceInfoJson? y) { return x?.Line == y?.Line; } + public bool Equals(SourceInfoJson x, SourceInfoJson y) { + return x.Line == y.Line; + } + public int GetHashCode(SourceInfoJson obj) { return obj.Line.GetHashCode(); }