Skip to content

Commit

Permalink
Replace LINQ's .Any() with foreach in Encode (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
aradalvand authored Sep 14, 2023
1 parent 7b6be39 commit ab87dad
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Sqids/SqidsEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,16 @@ public string Encode(params int[] numbers)
if (numbers.Length == 0)
return string.Empty;

foreach (var number in numbers)
#if NET7_0_OR_GREATER
if (numbers.Any(n => n < T.Zero))
if (number < T.Zero)
#else
if (numbers.Any(n => n < 0))
if (number < 0)
#endif
throw new ArgumentOutOfRangeException(
nameof(numbers),
"Encoding is only supported for zero and positive numbers."
);
throw new ArgumentOutOfRangeException(
nameof(numbers),
"Encoding is only supported for zero and positive numbers."
);

return Encode(numbers.AsSpan());
}
Expand Down

0 comments on commit ab87dad

Please sign in to comment.