Skip to content

Commit

Permalink
Fix GlobalComparer.cs boxing regression
Browse files Browse the repository at this point in the history
  • Loading branch information
halgari committed Oct 30, 2024
1 parent 24d83aa commit f366ac6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Changelog

### 0.9.92 - 30/10/2024
* Fix a regression in the GlobalCompare that was boxing an enum (resulting in a lot of allocations)

### 0.9.91 - 15/10/2024
* Attempt to fix an issue with Nuget and package resolution

Expand Down
13 changes: 9 additions & 4 deletions src/NexusMods.MnemonicDB.Abstractions/GlobalComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static unsafe int Compare(byte* aPtr, int aLen, byte* bPtr, int bLen)
var prefixA = (KeyPrefix*)aPtr;
var prefixB = (KeyPrefix*)bPtr;

var cmp = prefixA->Index.CompareTo(prefixB->Index);
var cmp = ((byte)prefixA->Index).CompareTo((byte)prefixB->Index);
if (cmp != 0)
return cmp;

Expand All @@ -30,13 +30,13 @@ public static unsafe int Compare(byte* aPtr, int aLen, byte* bPtr, int bLen)
IndexType.AEVTCurrent or IndexType.AEVTHistory => AEVTComparator.Compare(aPtr, aLen, bPtr, bLen),
IndexType.AVETCurrent or IndexType.AVETHistory => AVETComparator.Compare(aPtr, aLen, bPtr, bLen),
IndexType.VAETCurrent or IndexType.VAETHistory => VAETComparator.Compare(aPtr, aLen, bPtr, bLen),
_ => throw new ArgumentOutOfRangeException()
_ => ThrowArgumentOutOfRangeException()
};
}

public static int Compare(in Datom a, in Datom b)
{
var cmp = a.Prefix.Index.CompareTo(b.Prefix.Index);
var cmp = ((byte)a.Prefix.Index).CompareTo((byte)b.Prefix.Index);
if (cmp != 0)
return cmp;

Expand All @@ -47,10 +47,15 @@ public static int Compare(in Datom a, in Datom b)
IndexType.AEVTCurrent or IndexType.AEVTHistory => AEVTComparator.Compare(a, b),
IndexType.AVETCurrent or IndexType.AVETHistory => AVETComparator.Compare(a, b),
IndexType.VAETCurrent or IndexType.VAETHistory => VAETComparator.Compare(a, b),
_ => throw new ArgumentOutOfRangeException()
_ => ThrowArgumentOutOfRangeException()
};
}

private static int ThrowArgumentOutOfRangeException()
{
throw new ArgumentOutOfRangeException();
}

/// <inheritdoc />
public unsafe int Compare(byte[]? x, byte[]? y)
{
Expand Down

0 comments on commit f366ac6

Please sign in to comment.