Skip to content

Commit

Permalink
Use new collection expression of ReadOnlySpan only for .NET 8+
Browse files Browse the repository at this point in the history
  • Loading branch information
LeaFrock committed Nov 22, 2023
1 parent fdc4f13 commit d81737c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Sqids/SqidsEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,13 @@ public string Encode(int number)
nameof(number),
"Encoding is only supported for zero and positive numbers."
);

return Encode(stackalloc[] { number }); // NOTE: We use `stackalloc` here in order not to incur the cost of allocating an array on the heap, since we know the array will only have one element, we can use `stackalloc` safely.
#endif

return Encode([number]); // NOTE: We use `stackalloc` here in order not to incur the cost of allocating an array on the heap, since we know the array will only have one element, we can use `stackalloc` safely.
#if NET8_0_OR_GREATER
return Encode([number]);
#endif
}

/// <summary>
Expand Down

0 comments on commit d81737c

Please sign in to comment.