Skip to content

Commit

Permalink
Cache GetCountIndicatorLength
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane32 committed Apr 30, 2024
1 parent 1104e2a commit 4ab38e4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions QRCoder/QRCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,11 @@ public static QRCodeData GenerateQrCode(string plainText, ECCLevel eccLevel, boo
}
}

var countIndicatorLength = GetCountIndicatorLength(version, encoding);

var completeBitArrayLength =
(eciMode != EciMode.Default ? 16 : 4) + // Mode indicator
GetCountIndicatorLength(version, encoding) + // Count indicator
countIndicatorLength + // Count indicator
codedText.Length; // Data

var completeBitArray = new BitArray(completeBitArrayLength);
Expand All @@ -171,7 +173,7 @@ public static QRCodeData GenerateQrCode(string plainText, ECCLevel eccLevel, boo
}
DecToBin((int)encoding, 4, completeBitArray, ref completeBitArrayIndex);
// write count indicator
DecToBin(dataInputLength, GetCountIndicatorLength(version, encoding), completeBitArray, ref completeBitArrayIndex);
DecToBin(dataInputLength, countIndicatorLength, completeBitArray, ref completeBitArrayIndex);
// write data
for (int i = 0; i < codedText.Length; i++)
{
Expand Down

0 comments on commit 4ab38e4

Please sign in to comment.