Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed HashCode not being Case Insensitive, Improved HashCode Performance & Use SIMD/Intrinsics Code from External Library (Fixes #25) #31

Merged
merged 4 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 0 additions & 67 deletions src/NexusMods.Paths.Benchmarks/Benchmarks/ChangeCase.cs

This file was deleted.

This file was deleted.

125 changes: 0 additions & 125 deletions src/NexusMods.Paths.Benchmarks/Benchmarks/VectorisedStringHash.cs

This file was deleted.

14 changes: 8 additions & 6 deletions src/NexusMods.Paths/AbsolutePath.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using JetBrains.Annotations;
using NexusMods.Paths.Extensions;
using NexusMods.Paths.Utilities;
using Reloaded.Memory.Extensions;

[assembly: InternalsVisibleTo("NexusMods.Paths.Tests")]
namespace NexusMods.Paths;
Expand Down Expand Up @@ -327,8 +326,9 @@ public override string ToString()
/// <inheritdoc />
public bool Equals(AbsolutePath other)
{
return string.Equals(Directory, other.Directory, StringComparison.OrdinalIgnoreCase) &&
string.Equals(FileName, other.FileName, StringComparison.OrdinalIgnoreCase);
// Do not reorder, FileName is statistically more likely to mismatch than Directory - (Sewer)
return string.Equals(FileName, other.FileName, StringComparison.OrdinalIgnoreCase) &&
string.Equals(Directory, other.Directory, StringComparison.OrdinalIgnoreCase);
}

/// <inheritdoc />
Expand All @@ -340,8 +340,10 @@ public override bool Equals(object? obj)
/// <inheritdoc />
public override int GetHashCode()
{
var a = string.GetHashCode(Directory, StringComparison.OrdinalIgnoreCase);
var b = string.GetHashCode(FileName, StringComparison.OrdinalIgnoreCase);
// A custom HashCode, based on FNV-1 with added Vectorization because the default one is very slow for our use in trees, dictionaries, etc.
// .NET does have a faster hashcode for strings, however it is not exposed (and is 5x slower than custom one anyways).
var a = Directory.GetHashCodeLowerFast();
var b = FileName.GetHashCodeLowerFast();
return HashCode.Combine(a, b);
}
#endregion
Expand Down
Loading