diff --git a/Benchmark/BenchmarkAHashString.cs b/Benchmark/BenchmarkAHashString.cs index bed4c35..e54ed4e 100644 --- a/Benchmark/BenchmarkAHashString.cs +++ b/Benchmark/BenchmarkAHashString.cs @@ -15,7 +15,7 @@ public class BenchmarkAHashString { [Params("asd", "1234567890", "1234567890_1234567890_1234567890_1234567890", "1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890")] - public string Str; + public string? Str; #if NET8_0_OR_GREATER [Benchmark] diff --git a/BetterCollections/BetterCollections.csproj b/BetterCollections/BetterCollections.csproj index fcf9c58..340458e 100644 --- a/BetterCollections/BetterCollections.csproj +++ b/BetterCollections/BetterCollections.csproj @@ -5,7 +5,7 @@ 12.0 enable true - 0.3.1 + 0.3.2 https://github.com/libsugar/BetterCollections Some better collection implementations than the standard library README.md diff --git a/BetterCollections/Memories/Box.cs b/BetterCollections/Memories/Box.cs index b0db93d..65ec499 100644 --- a/BetterCollections/Memories/Box.cs +++ b/BetterCollections/Memories/Box.cs @@ -4,6 +4,24 @@ namespace BetterCollections.Memories; +public static class Box +{ + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Box Make(T value) => new(value); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlyBox MakeReadOnly(T value) => new(value); +} + +public static class BoxEx +{ + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Box Box(this T value) => new(value); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlyBox ReadOnlyBox(this T value) => new(value); +} + public class Box(T Value) : IRef, IReadOnlyRef, IStrongBox, IEquatable, IEquatable>, IComparable, IComparable> @@ -26,7 +44,7 @@ public class Box(T Value) : IRef, IReadOnlyRef, IStrongBox, public bool Equals(T? other) => EqualityComparer.Default.Equals(Value, other!); - public bool Equals(Box? other) => ReferenceEquals(other, null) && Equals(other!.Value); + public bool Equals(Box? other) => !ReferenceEquals(other, null) && Equals(other.Value); public override bool Equals(object? obj) => obj is Box box ? Equals(box) : obj is T v && Equals(v); @@ -100,7 +118,7 @@ public class ReadOnlyBox(T Value) : IReadOnlyRef, public bool Equals(T? other) => EqualityComparer.Default.Equals(Value, other!); - public bool Equals(ReadOnlyBox? other) => ReferenceEquals(other, null) && Equals(other!.Value); + public bool Equals(ReadOnlyBox? other) => !ReferenceEquals(other, null) && Equals(other.Value); public override bool Equals(object? obj) => obj is ReadOnlyBox box ? Equals(box) : obj is T v && Equals(v);