diff --git a/src/DotNext.Threading/Collections/Concurrent/IndexPool.cs b/src/DotNext.Threading/Collections/Concurrent/IndexPool.cs index ae36d1d07..79562efd1 100644 --- a/src/DotNext.Threading/Collections/Concurrent/IndexPool.cs +++ b/src/DotNext.Threading/Collections/Concurrent/IndexPool.cs @@ -39,7 +39,7 @@ public IndexPool() /// public IndexPool(int maxValue) { - if (maxValue < 0 || maxValue > MaxValue) + if ((uint)maxValue > (uint)MaxValue) throw new ArgumentOutOfRangeException(nameof(maxValue)); bitmask = ulong.MaxValue; @@ -148,7 +148,7 @@ public int Take(Span indicies) /// value specified for this pool. public void Return(int value) { - if (value < 0 || value > maxValue) + if ((uint)value > (uint)maxValue) ThrowArgumentOutOfRangeException(); Interlocked.Or(ref bitmask, 1UL << value); @@ -184,7 +184,7 @@ public void Return(ReadOnlySpan indicies) /// The value to check. /// if is available for rent; otherwise, . public readonly bool Contains(int value) - => value >= 0 && value <= maxValue && Contains(Volatile.Read(in bitmask), value); + => (uint)value <= (uint)maxValue && Contains(Volatile.Read(in bitmask), value); private static bool Contains(ulong bitmask, int index) => (bitmask & (1UL << index)) is not 0UL;