From d81737c7a5c268c51b43594ebc13062a05476877 Mon Sep 17 00:00:00 2001 From: LeaFrock Date: Wed, 22 Nov 2023 18:38:00 +0800 Subject: [PATCH] Use new collection expression of `ReadOnlySpan` only for .NET 8+ --- src/Sqids/SqidsEncoder.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Sqids/SqidsEncoder.cs b/src/Sqids/SqidsEncoder.cs index 30ab707..6a8e199 100644 --- a/src/Sqids/SqidsEncoder.cs +++ b/src/Sqids/SqidsEncoder.cs @@ -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 } ///