diff --git a/csharp/Platform.Data.Tests/LinksConstantsTests.cs b/csharp/Platform.Data.Tests/LinksConstantsTests.cs index 93a3526a..8cad5652 100644 --- a/csharp/Platform.Data.Tests/LinksConstantsTests.cs +++ b/csharp/Platform.Data.Tests/LinksConstantsTests.cs @@ -1,3 +1,4 @@ +using System.Numerics; using Xunit; using Platform.Reflection; using Platform.Converters; @@ -41,12 +42,11 @@ public static void ExternalReferencesTest() TestExternalReferences(); TestExternalReferences(); } - private static void TestExternalReferences() + private static void TestExternalReferences() where TUnsigned : IUnsignedNumber where TSigned : ISignedNumber { - var unsingedOne = Arithmetic.Increment(default(TUnsigned)); - var converter = UncheckedConverter.Default; - var half = converter.Convert(NumericType.MaxValue); - LinksConstants constants = new LinksConstants((unsingedOne, half), (Arithmetic.Add(half, unsingedOne), NumericType.MaxValue)); + var unsingedOne = TUnsigned.One; + var half = TUnsigned.CreateTruncating((NumericType.MaxValue)); + LinksConstants constants = new LinksConstants((unsingedOne, half), (half+unsingedOne, NumericType.MaxValue)); var minimum = new Hybrid(default, isExternal: true); var maximum = new Hybrid(half, isExternal: true); diff --git a/csharp/Platform.Data/Hybrid.cs b/csharp/Platform.Data/Hybrid.cs index 149e20b2..93ce0a16 100644 --- a/csharp/Platform.Data/Hybrid.cs +++ b/csharp/Platform.Data/Hybrid.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; +using System.Numerics; using System.Runtime.CompilerServices; using Platform.Exceptions; using Platform.Reflection; using Platform.Converters; using Platform.Numbers; +using Math = System.Math; #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member @@ -16,13 +18,9 @@ namespace Platform.Data /// /// /// - public struct Hybrid : IEquatable> + public struct Hybrid : IEquatable> where TLinkAddress:IUnsignedNumber { - private static readonly EqualityComparer _equalityComparer = EqualityComparer.Default; private static readonly UncheckedSignExtendingConverter _addressToInt64Converter = UncheckedSignExtendingConverter.Default; - private static readonly UncheckedConverter _int64ToAddressConverter = UncheckedConverter.Default; - private static readonly UncheckedConverter _addressToUInt64Converter = UncheckedConverter.Default; - private static readonly UncheckedConverter _uInt64ToAddressConverter = UncheckedConverter.Default; private static readonly UncheckedConverter _objectToInt64Converter = UncheckedConverter.Default; /// @@ -31,14 +29,14 @@ public struct Hybrid : IEquatable> /// /// /// - public static readonly ulong HalfOfNumberValuesRange = _addressToUInt64Converter.Convert(NumericType.MaxValue) / 2; + public static readonly TLinkAddress HalfOfNumberValuesRange = (NumericType.MaxValue) / TLinkAddress.CreateTruncating(2); /// /// /// The half of number values range. /// /// /// - public static readonly TLinkAddress ExternalZero = _uInt64ToAddressConverter.Convert(HalfOfNumberValuesRange + 1UL); + public static readonly TLinkAddress ExternalZero = (HalfOfNumberValuesRange + TLinkAddress.CreateTruncating(1)); /// /// @@ -57,7 +55,7 @@ public struct Hybrid : IEquatable> public bool IsNothing { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _equalityComparer.Equals(Value, ExternalZero) || SignedValue == 0; + get => (Value == ExternalZero) || SignedValue == 0; } /// @@ -81,7 +79,7 @@ public bool IsInternal public bool IsExternal { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _equalityComparer.Equals(Value, ExternalZero) || SignedValue < 0; + get => (Value == ExternalZero) || SignedValue < 0; } /// @@ -105,7 +103,7 @@ public long SignedValue public long AbsoluteValue { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _equalityComparer.Equals(Value, ExternalZero) ? 0 : Platform.Numbers.Math.Abs(SignedValue); + get => (Value == ExternalZero) ? 0 : System.Math.Abs(SignedValue); } /// @@ -142,7 +140,7 @@ public Hybrid(TLinkAddress value) [MethodImpl(MethodImplOptions.AggressiveInlining)] public Hybrid(TLinkAddress value, bool isExternal) { - if (_equalityComparer.Equals(value, default) && isExternal) + if ((value == default) && isExternal) { Value = ExternalZero; } @@ -150,7 +148,7 @@ public Hybrid(TLinkAddress value, bool isExternal) { if (isExternal) { - Value = Math.Negate(value); + Value = -(value); } else { @@ -170,7 +168,7 @@ public Hybrid(TLinkAddress value, bool isExternal) /// /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Hybrid(object value) => Value = _int64ToAddressConverter.Convert(_objectToInt64Converter.Convert(value)); + public Hybrid(object value) => Value = TLinkAddress.CreateTruncating(_objectToInt64Converter.Convert(value)); /// /// @@ -197,7 +195,7 @@ public Hybrid(object value, bool isExternal) else { var absoluteValue = System.Math.Abs(signedValue); - Value = isExternal ? _int64ToAddressConverter.Convert(-absoluteValue) : _int64ToAddressConverter.Convert(absoluteValue); + Value = isExternal ? TLinkAddress.CreateTruncating(-absoluteValue) : TLinkAddress.CreateTruncating(absoluteValue); } } @@ -283,7 +281,7 @@ public Hybrid(object value, bool isExternal) /// /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(Hybrid other) => _equalityComparer.Equals(Value, other.Value); + public bool Equals(Hybrid other) => (Value == other.Value); /// /// diff --git a/csharp/Platform.Data/ILinks.cs b/csharp/Platform.Data/ILinks.cs index a6bc5580..7438b68c 100644 --- a/csharp/Platform.Data/ILinks.cs +++ b/csharp/Platform.Data/ILinks.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Numerics; using System.Runtime.CompilerServices; using Platform.Delegates; @@ -16,6 +17,7 @@ namespace Platform.Data /// Этот интерфейс не зависит от размера содержимого связи, а значит подходит как для дуплетов, триплетов и последовательностей связей любого размера. /// public interface ILinks + where TLinkAddress : IUnsignedNumber where TConstants : LinksConstants { #region Constants diff --git a/csharp/Platform.Data/ILinksExtensions.cs b/csharp/Platform.Data/ILinksExtensions.cs index ace8dfeb..4fcf77a7 100644 --- a/csharp/Platform.Data/ILinksExtensions.cs +++ b/csharp/Platform.Data/ILinksExtensions.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Numerics; using System.Runtime.CompilerServices; using Platform.Setters; using Platform.Data.Exceptions; @@ -17,9 +18,9 @@ namespace Platform.Data /// public static class ILinksExtensions { - public static TLinkAddress Create(this ILinks> links) => links.Create(null); + public static TLinkAddress Create(this ILinks> links) where TLinkAddress : IUnsignedNumber => links.Create(null); - public static TLinkAddress Create(this ILinks> links, IList? substitution) + public static TLinkAddress Create(this ILinks> links, IList? substitution) where TLinkAddress : IUnsignedNumber { var constants = links.Constants; Setter setter = new Setter(constants.Continue, constants.Break, constants.Null); @@ -27,7 +28,7 @@ public static TLinkAddress Create(this ILinks(this ILinks> links, IList? restriction, IList? substitution) + public static TLinkAddress Update(this ILinks> links, IList? restriction, IList? substitution) where TLinkAddress : IUnsignedNumber { var constants = links.Constants; Setter setter = new(constants.Continue, constants.Break, constants.Null); @@ -35,9 +36,9 @@ public static TLinkAddress Update(this ILinks(this ILinks> links, TLinkAddress linkToDelete) => Delete(links, (IList?)new LinkAddress(linkToDelete)); + public static TLinkAddress Delete(this ILinks> links, TLinkAddress linkToDelete) where TLinkAddress : IUnsignedNumber => Delete(links, (IList?)new LinkAddress(linkToDelete)); - public static TLinkAddress Delete(this ILinks> links, IList? restriction) + public static TLinkAddress Delete(this ILinks> links, IList? restriction) where TLinkAddress : IUnsignedNumber { var constants = links.Constants; Setter setter = new Setter(constants.Continue, constants.Break, constants.Null); @@ -72,7 +73,7 @@ public static TLinkAddress Delete(this ILinks /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static TLinkAddress Count(this ILinks links, params TLinkAddress[] restrictions) + public static TLinkAddress Count(this ILinks links, params TLinkAddress[] restrictions) where TLinkAddress : IUnsignedNumber where TConstants : LinksConstants => links.Count(restrictions); @@ -83,7 +84,7 @@ public static TLinkAddress Count(this ILinksИндекс проверяемой на существование связи. /// Значение, определяющее существует ли связь. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Exists(this ILinks links, TLinkAddress link) + public static bool Exists(this ILinks links, TLinkAddress link) where TLinkAddress : IUnsignedNumber where TConstants : LinksConstants { var constants = links.Constants; @@ -96,7 +97,7 @@ public static bool Exists(this ILinks [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void EnsureLinkExists(this ILinks links, TLinkAddress link) + public static void EnsureLinkExists(this ILinks links, TLinkAddress link) where TLinkAddress : IUnsignedNumber where TConstants : LinksConstants { if (!links.Exists(link)) @@ -109,7 +110,7 @@ public static void EnsureLinkExists(this ILinksИндекс проверяемой на существование связи. /// Имя аргумента, в который передаётся индекс связи. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void EnsureLinkExists(this ILinks links, TLinkAddress link, string argumentName) + public static void EnsureLinkExists(this ILinks links, TLinkAddress link, string argumentName) where TLinkAddress : IUnsignedNumber where TConstants : LinksConstants { if (!links.Exists(link)) @@ -126,7 +127,7 @@ public static void EnsureLinkExists(this ILinksОграничения на содержимое связей. Каждое ограничение может иметь значения: Constants.Null - 0-я связь, обозначающая ссылку на пустоту, Any - отсутствие ограничения, 1..∞ конкретный индекс связи. /// True, в случае если проход по связям не был прерван и False в обратном случае. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static TLinkAddress Each(this ILinks links, ReadHandler? handler, params TLinkAddress[] restrictions) + public static TLinkAddress Each(this ILinks links, ReadHandler? handler, params TLinkAddress[] restrictions) where TLinkAddress : IUnsignedNumber where TConstants : LinksConstants => links.Each(restrictions, handler); @@ -137,7 +138,7 @@ public static TLinkAddress Each(this ILinksИндекс связи. /// Уникальную связь. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static IList? GetLink(this ILinks links, TLinkAddress link) + public static IList? GetLink(this ILinks links, TLinkAddress link) where TLinkAddress : IUnsignedNumber where TConstants : LinksConstants { var constants = links.Constants; @@ -175,7 +176,7 @@ public static TLinkAddress Each(this ILinks [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool IsFullPoint(this ILinks links, TLinkAddress link) + public static bool IsFullPoint(this ILinks links, TLinkAddress link) where TLinkAddress : IUnsignedNumber where TConstants : LinksConstants { if (links.Constants.IsExternalReference(link)) @@ -195,7 +196,7 @@ public static bool IsFullPoint(this ILinks [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool IsPartialPoint(this ILinks links, TLinkAddress link) + public static bool IsPartialPoint(this ILinks links, TLinkAddress link) where TLinkAddress : IUnsignedNumber where TConstants : LinksConstants { if (links.Constants.IsExternalReference(link)) diff --git a/csharp/Platform.Data/ISynchronizedLinks.cs b/csharp/Platform.Data/ISynchronizedLinks.cs index 0e2a7f11..d536b128 100644 --- a/csharp/Platform.Data/ISynchronizedLinks.cs +++ b/csharp/Platform.Data/ISynchronizedLinks.cs @@ -1,3 +1,4 @@ +using System.Numerics; using Platform.Threading.Synchronization; #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member @@ -13,6 +14,7 @@ namespace Platform.Data /// /// public interface ISynchronizedLinks : ISynchronized, ILinks + where TLinkAddress : IUnsignedNumber where TLinks : ILinks where TConstants : LinksConstants { diff --git a/csharp/Platform.Data/LinkAddress.cs b/csharp/Platform.Data/LinkAddress.cs index b7697034..91c9d818 100644 --- a/csharp/Platform.Data/LinkAddress.cs +++ b/csharp/Platform.Data/LinkAddress.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Numerics; using System.Runtime.CompilerServices; #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member @@ -15,9 +16,8 @@ namespace Platform.Data /// /// /// - public class LinkAddress : IEquatable>, IList + public class LinkAddress : IEquatable>, IList where TLinkAddress : IUnsignedNumber { - private static readonly EqualityComparer _equalityComparer = EqualityComparer.Default; /// /// @@ -129,7 +129,7 @@ public bool IsReadOnly /// /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public virtual bool Contains(TLinkAddress item) => _equalityComparer.Equals(item, Index); + public virtual bool Contains(TLinkAddress item) => (item == Index); /// /// @@ -179,7 +179,7 @@ public IEnumerator GetEnumerator() /// /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public virtual int IndexOf(TLinkAddress item) => _equalityComparer.Equals(item, Index) ? 0 : -1; + public virtual int IndexOf(TLinkAddress item) => (item == Index) ? 0 : -1; /// /// @@ -259,7 +259,7 @@ IEnumerator IEnumerable.GetEnumerator() /// /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public virtual bool Equals(LinkAddress other) => other != null && _equalityComparer.Equals(Index, other.Index); + public virtual bool Equals(LinkAddress other) => other != null && (Index == other.Index); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator TLinkAddress(LinkAddress linkAddress) => linkAddress.Index; diff --git a/csharp/Platform.Data/LinksConstants.cs b/csharp/Platform.Data/LinksConstants.cs index 8f810bd7..f2df4f9f 100644 --- a/csharp/Platform.Data/LinksConstants.cs +++ b/csharp/Platform.Data/LinksConstants.cs @@ -1,3 +1,4 @@ +using System.Numerics; using System.Runtime.CompilerServices; using Platform.Ranges; using Platform.Reflection; @@ -15,9 +16,8 @@ namespace Platform.Data /// /// /// - public class LinksConstants : LinksConstantsBase + public class LinksConstants : LinksConstantsBase where TLinkAddress : IUnsignedNumber { - private static readonly TLinkAddress _one = Arithmetic.Increment(default); private static readonly UncheckedConverter _uInt64ToAddressConverter = UncheckedConverter.Default; #region Link parts @@ -145,12 +145,12 @@ public LinksConstants(int targetPart, Range possibleInternalRefere var currentInternalReferenceIndex = possibleInternalReferencesRange.Maximum; Null = default; Continue = currentInternalReferenceIndex; - Break = Arithmetic.Decrement(ref currentInternalReferenceIndex); - Skip = Arithmetic.Decrement(ref currentInternalReferenceIndex); - Any = Arithmetic.Decrement(ref currentInternalReferenceIndex); - Itself = Arithmetic.Decrement(ref currentInternalReferenceIndex); - Error = Arithmetic.Decrement(ref currentInternalReferenceIndex); - Arithmetic.Decrement(ref currentInternalReferenceIndex); + Break = --currentInternalReferenceIndex; + Skip = --currentInternalReferenceIndex; + Any = --currentInternalReferenceIndex; + Itself = --currentInternalReferenceIndex; + Error = --currentInternalReferenceIndex; + --currentInternalReferenceIndex; InternalReferencesRange = (possibleInternalReferencesRange.Minimum, currentInternalReferenceIndex); ExternalReferencesRange = possibleExternalReferencesRange; } @@ -260,11 +260,11 @@ public static Range GetDefaultInternalReferencesRange(bool enableE { if (enableExternalReferencesSupport) { - return (_one, _uInt64ToAddressConverter.Convert(Hybrid.HalfOfNumberValuesRange)); + return (TLinkAddress.One, Hybrid.HalfOfNumberValuesRange); } else { - return (_one, NumericType.MaxValue); + return (TLinkAddress.One, NumericType.MaxValue); } } diff --git a/csharp/Platform.Data/LinksConstantsExtensions.cs b/csharp/Platform.Data/LinksConstantsExtensions.cs index ae384cab..92e4f718 100644 --- a/csharp/Platform.Data/LinksConstantsExtensions.cs +++ b/csharp/Platform.Data/LinksConstantsExtensions.cs @@ -1,5 +1,6 @@ #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member +using System.Numerics; using System.Runtime.CompilerServices; namespace Platform.Data @@ -35,7 +36,7 @@ public static class LinksConstantsExtensions /// /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool IsReference(this LinksConstants linksConstants, TLinkAddress address) => linksConstants.IsInternalReference(address) || linksConstants.IsExternalReference(address); + public static bool IsReference(this LinksConstants linksConstants, TLinkAddress address) where TLinkAddress : IUnsignedNumber => linksConstants.IsInternalReference(address) || linksConstants.IsExternalReference(address); /// /// @@ -60,7 +61,7 @@ public static class LinksConstantsExtensions /// /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool IsInternalReference(this LinksConstants linksConstants, TLinkAddress address) => linksConstants.InternalReferencesRange.Contains(address); + public static bool IsInternalReference(this LinksConstants linksConstants, TLinkAddress address) where TLinkAddress : IUnsignedNumber => linksConstants.InternalReferencesRange.Contains(address); /// /// @@ -85,6 +86,6 @@ public static class LinksConstantsExtensions /// /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool IsExternalReference(this LinksConstants linksConstants, TLinkAddress address) => linksConstants.ExternalReferencesRange?.Contains(address) ?? false; + public static bool IsExternalReference(this LinksConstants linksConstants, TLinkAddress address) where TLinkAddress : IUnsignedNumber => linksConstants.ExternalReferencesRange?.Contains(address) ?? false; } } diff --git a/csharp/Platform.Data/Numbers/Raw/AddressToRawNumberConverter.cs b/csharp/Platform.Data/Numbers/Raw/AddressToRawNumberConverter.cs index bc3852ee..94093d44 100644 --- a/csharp/Platform.Data/Numbers/Raw/AddressToRawNumberConverter.cs +++ b/csharp/Platform.Data/Numbers/Raw/AddressToRawNumberConverter.cs @@ -1,3 +1,4 @@ +using System.Numerics; using System.Runtime.CompilerServices; using Platform.Converters; @@ -12,7 +13,7 @@ namespace Platform.Data.Numbers.Raw /// /// /// - public class AddressToRawNumberConverter : IConverter + public class AddressToRawNumberConverter : IConverter where TLinkAddress : IUnsignedNumber { /// /// diff --git a/csharp/Platform.Data/Numbers/Raw/RawNumberToAddressConverter.cs b/csharp/Platform.Data/Numbers/Raw/RawNumberToAddressConverter.cs index 37a3f04a..808333ab 100644 --- a/csharp/Platform.Data/Numbers/Raw/RawNumberToAddressConverter.cs +++ b/csharp/Platform.Data/Numbers/Raw/RawNumberToAddressConverter.cs @@ -1,3 +1,4 @@ +using System.Numerics; using System.Runtime.CompilerServices; using Platform.Converters; @@ -12,7 +13,7 @@ namespace Platform.Data.Numbers.Raw /// /// /// - public class RawNumberToAddressConverter : IConverter + public class RawNumberToAddressConverter : IConverter where TLinkAddress : IUnsignedNumber { /// /// diff --git a/csharp/Platform.Data/Platform.Data.csproj b/csharp/Platform.Data/Platform.Data.csproj index e112f129..2a904c44 100644 --- a/csharp/Platform.Data/Platform.Data.csproj +++ b/csharp/Platform.Data/Platform.Data.csproj @@ -4,7 +4,7 @@ LinksPlatform's Platform.Data Class Library konard, FreePhoenix888 Platform.Data - 0.12.1 + 0.13.0 konard, FreePhoenix888 net7 Platform.Data @@ -23,7 +23,7 @@ true snupkg latest - Platform.Numbers dependency is updated from 0.6.2 to 0.7.0. + Generic constraints are added. enable diff --git a/csharp/Platform.Data/Point.cs b/csharp/Platform.Data/Point.cs index cbe55dad..b1ed34bb 100644 --- a/csharp/Platform.Data/Point.cs +++ b/csharp/Platform.Data/Point.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Numerics; using System.Runtime.CompilerServices; using Platform.Exceptions; using Platform.Ranges; @@ -18,9 +19,8 @@ namespace Platform.Data /// /// /// - public class Point : IEquatable>, IList + public class Point : IEquatable>, IList where TLinkAddress : IUnsignedNumber { - private static readonly EqualityComparer _equalityComparer = EqualityComparer.Default; /// /// @@ -152,7 +152,7 @@ public Point(TLinkAddress index, int size) /// /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public virtual bool Contains(TLinkAddress item) => _equalityComparer.Equals(item, Index); + public virtual bool Contains(TLinkAddress item) => (item == Index); /// /// @@ -205,7 +205,7 @@ public IEnumerator GetEnumerator() /// /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public virtual int IndexOf(TLinkAddress item) => _equalityComparer.Equals(item, Index) ? 0 : -1; + public virtual int IndexOf(TLinkAddress item) => (item == Index) ? 0 : -1; /// /// @@ -288,7 +288,7 @@ IEnumerator IEnumerable.GetEnumerator() /// /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public virtual bool Equals(LinkAddress other) => other == null ? false : _equalityComparer.Equals(Index, other.Index); + public virtual bool Equals(LinkAddress other) => other == null ? false : (Index == other.Index); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator TLinkAddress(Point linkAddress) => linkAddress.Index; @@ -412,7 +412,7 @@ public static bool IsFullPointUnchecked(IList? link) var result = true; for (var i = 1; result && i < link.Count; i++) { - result = _equalityComparer.Equals(link[0], link[i]); + result = (link[0] == link[i]); } return result; } @@ -476,7 +476,7 @@ public static bool IsPartialPointUnchecked(IList? link) var result = false; for (var i = 1; !result && i < link.Count; i++) { - result = _equalityComparer.Equals(link[0], link[i]); + result = (link[0] == link[i]); } return result; } diff --git a/csharp/Platform.Data/WriteHandlerState.cs b/csharp/Platform.Data/WriteHandlerState.cs index 55cab361..058383ed 100644 --- a/csharp/Platform.Data/WriteHandlerState.cs +++ b/csharp/Platform.Data/WriteHandlerState.cs @@ -1,18 +1,17 @@ using System.Collections.Generic; +using System.Numerics; using Platform.Delegates; namespace Platform.Data { - public struct WriteHandlerState + public struct WriteHandlerState where TLinkAddress : IUnsignedNumber { - private readonly EqualityComparer _equalityComparer; public TLinkAddress Result; public WriteHandler? Handler; private TLinkAddress Break; public WriteHandlerState(TLinkAddress @continue, TLinkAddress @break, WriteHandler? handler) { - _equalityComparer = EqualityComparer.Default; Break = @break; Result = @continue; Handler = handler; @@ -20,8 +19,8 @@ public WriteHandlerState(TLinkAddress @continue, TLinkAddress @break, WriteHandl public void Apply(TLinkAddress result) { - var isAlreadyBreak = _equalityComparer.Equals(Break, Result); - var isCurrentlyBreak = _equalityComparer.Equals(Break, result); + var isAlreadyBreak = (Break == Result); + var isCurrentlyBreak = (Break == result); if (isAlreadyBreak || !isCurrentlyBreak) { return;