Skip to content

Commit

Permalink
Update ifdef
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane32 committed May 7, 2024
1 parent 554c527 commit cb5a497
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions QRCoder/QRCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -935,9 +935,8 @@ private static BitArray PlainTextToBinaryByte(string plainText, EciMode eciMode,
}
}

#if NETCOREAPP2_1_OR_GREATER
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1
// We can use stackalloc for small arrays to prevent heap allocations
// (also available in .NET Standard and .NET Framework with an additional NuGet dependency)
// Note that all QR codes should fit within 3000 bytes, so this code should never trigger a heap allocation unless an exception will be thrown anyway.
int count = targetEncoding.GetByteCount(plainText);
Span<byte> codeBytes = count < 3000 ? stackalloc byte[count] : new byte[count];
Expand Down Expand Up @@ -971,7 +970,7 @@ private static BitArray PlainTextToBinaryByte(string plainText, EciMode eciMode,
/// <param name="prefixZeros">The number of leading zeros to prepend to the resulting BitArray.</param>
/// <returns>A BitArray representing the bits of the input byteArray, with optional leading zeros.</returns>
private static BitArray ToBitArray(
#if NET5_0_OR_GREATER
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1
ReadOnlySpan<byte> byteArray, // byte[] has an implicit cast to ReadOnlySpan<byte>
#else
byte[] byteArray,
Expand Down

0 comments on commit cb5a497

Please sign in to comment.