Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchLeaders committed Jan 20, 2025
1 parent 4515a1d commit c1808e6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
26 changes: 10 additions & 16 deletions src/BymlLibrary/Byml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public enum BymlChangeType
public enum BymlNodeType : byte
{
None = 0x0,

// A better solution could be
// used for handling these map tyes
HashMap32 = 0x20,
Expand Down Expand Up @@ -407,21 +407,15 @@ public BymlChangeType GetChangelog()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Get<T>()
{
if (Value is null) {
throw new InvalidOperationException($"""
Cannot parse null node
""");
}

if (Value is T value) {
return value;
}
return Value switch {
T value => value,
null => throw new InvalidOperationException("Cannot parse null node"),
_ => throw new InvalidDataException($"""
Unexpected type: '{typeof(T)}'
throw new InvalidDataException($"""
Unexpected type: '{typeof(T)}'
Expected '{typeof(T)}' but found '{Value.GetType()} ({Type})'
""");
Expected '{typeof(T)}' but found '{Value.GetType()} ({Type})'
""")
};
}

public class ValueEqualityComparer : IEqualityComparer<Byml>
Expand Down Expand Up @@ -513,4 +507,4 @@ private static bool CompareBinaryAligned((byte[] data, int alignment) x, (byte[]
return x.alignment == y.alignment && x.data.SequenceEqual(y.data);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class Reverser : IStructReverser
{
public static void Reverse(in Span<byte> slice)
{
slice[0..4].Reverse();
slice[..4].Reverse();
slice[4..8].Reverse();
slice[8..12].Reverse();
slice[12..16].Reverse();
Expand Down

0 comments on commit c1808e6

Please sign in to comment.