4
4
using System . Text ;
5
5
using System . Collections ;
6
6
using System . Globalization ;
7
+ using System . Runtime . CompilerServices ;
7
8
8
9
namespace QRCoder
9
10
{
@@ -154,12 +155,12 @@ public static QRCodeData GenerateQrCode(string plainText, ECCLevel eccLevel, boo
154
155
var completeBitArrayIndex = 0 ;
155
156
if ( eciMode != EciMode . Default )
156
157
{
157
- DecToBin ( ( int ) EncodingMode . ECI , 4 , completeBitArray , ref completeBitArrayIndex ) ;
158
- DecToBin ( ( int ) eciMode , 8 , completeBitArray , ref completeBitArrayIndex ) ;
158
+ completeBitArrayIndex = DecToBin ( ( int ) EncodingMode . ECI , 4 , completeBitArray , completeBitArrayIndex ) ;
159
+ completeBitArrayIndex = DecToBin ( ( int ) eciMode , 8 , completeBitArray , completeBitArrayIndex ) ;
159
160
}
160
- DecToBin ( ( int ) encoding , 4 , completeBitArray , ref completeBitArrayIndex ) ;
161
+ completeBitArrayIndex = DecToBin ( ( int ) encoding , 4 , completeBitArray , completeBitArrayIndex ) ;
161
162
// write count indicator
162
- DecToBin ( dataInputLength , countIndicatorLength , completeBitArray , ref completeBitArrayIndex ) ;
163
+ completeBitArrayIndex = DecToBin ( dataInputLength , countIndicatorLength , completeBitArray , completeBitArrayIndex ) ;
163
164
// write data
164
165
for ( int i = 0 ; i < codedText . Length ; i ++ )
165
166
{
@@ -185,9 +186,8 @@ public static QRCodeData GenerateQrCode(byte[] binaryData, ECCLevel eccLevel)
185
186
// Convert byte array to bit array, with prefix padding for mode indicator and count indicator
186
187
var bitArray = ToBitArray ( binaryData , prefixZeros : 4 + countIndicatorLen ) ;
187
188
// Add mode indicator and count indicator
188
- var index = 0 ;
189
- DecToBin ( ( int ) EncodingMode . Byte , 4 , bitArray , ref index ) ;
190
- DecToBin ( binaryData . Length , countIndicatorLen , bitArray , ref index ) ;
189
+ var index = DecToBin ( ( int ) EncodingMode . Byte , 4 , bitArray , 0 ) ;
190
+ DecToBin ( binaryData . Length , countIndicatorLen , bitArray , index ) ;
191
191
192
192
return GenerateQrCode ( bitArray , eccLevel , version ) ;
193
193
}
@@ -252,13 +252,13 @@ private static QRCodeData GenerateQrCode(BitArray bitArray, ECCLevel eccLevel, i
252
252
{
253
253
foreach ( var codeBlock in codeWordWithECC )
254
254
if ( codeBlock . CodeWords . Length > i )
255
- DecToBin ( codeBlock . CodeWords [ i ] , 8 , interleavedData , ref pos ) ;
255
+ pos = DecToBin ( codeBlock . CodeWords [ i ] , 8 , interleavedData , pos ) ;
256
256
}
257
257
for ( var i = 0 ; i < eccInfo . ECCPerBlock ; i ++ )
258
258
{
259
259
foreach ( var codeBlock in codeWordWithECC )
260
260
if ( codeBlock . ECCWords . Length > i )
261
- DecToBin ( codeBlock . ECCWords [ i ] , 8 , interleavedData , ref pos ) ;
261
+ pos = DecToBin ( codeBlock . ECCWords [ i ] , 8 , interleavedData , pos ) ;
262
262
}
263
263
264
264
//Place interleaved data on module matrix
@@ -341,10 +341,12 @@ void WriteEccLevelAndVersion()
341
341
default : // M: 00
342
342
break ;
343
343
}
344
- int indexTemp = 2 ;
345
- DecToBin ( maskVersion , 3 , fStrEcc , ref indexTemp ) ;
344
+ DecToBin ( maskVersion , 3 , fStrEcc , 2 ) ;
346
345
}
347
346
347
+ #if NETCOREAPP
348
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
349
+ #endif
348
350
void TrimLeadingZeros ( )
349
351
{
350
352
while ( ! fStrEcc [ index ] )
@@ -384,10 +386,9 @@ private static void ShiftAwayFromBit0(BitArray fStrEcc, int num)
384
386
private static BitArray GetVersionString ( int version )
385
387
{
386
388
var vStr = new BitArray ( 18 ) ;
387
- var index = 0 ;
388
- DecToBin ( version , 6 , vStr , ref index ) ;
389
+ DecToBin ( version , 6 , vStr , 0 ) ;
389
390
var count = vStr . Length ;
390
- index = 0 ;
391
+ var index = 0 ;
391
392
while ( ! vStr [ index ] )
392
393
{
393
394
index ++ ;
@@ -406,8 +407,7 @@ private static BitArray GetVersionString(int version)
406
407
ShiftTowardsBit0 ( vStr , index ) ;
407
408
vStr . Length = 12 + 6 ;
408
409
ShiftAwayFromBit0 ( vStr , ( 12 - count ) + 6 ) ;
409
- index = 0 ;
410
- DecToBin ( version , 6 , vStr , ref index ) ;
410
+ DecToBin ( version , 6 , vStr , 0 ) ;
411
411
return vStr ;
412
412
}
413
413
@@ -1043,7 +1043,7 @@ private static int BinToDec(BitArray bitArray, int offset, int count)
1043
1043
return ret ;
1044
1044
}
1045
1045
1046
- private static void DecToBin ( int decNum , int bits , BitArray bitList , ref int index )
1046
+ private static int DecToBin ( int decNum , int bits , BitArray bitList , int index )
1047
1047
{
1048
1048
// Convert decNum to binary using a bitwise operation
1049
1049
for ( int i = bits - 1 ; i >= 0 ; i -- )
@@ -1052,6 +1052,7 @@ private static void DecToBin(int decNum, int bits, BitArray bitList, ref int ind
1052
1052
bool bit = ( decNum & ( 1 << i ) ) != 0 ;
1053
1053
bitList [ index ++ ] = bit ;
1054
1054
}
1055
+ return index ;
1055
1056
}
1056
1057
1057
1058
private static int GetCountIndicatorLength ( int version , EncodingMode encMode )
@@ -1136,7 +1137,7 @@ private static BitArray PlainTextToBinaryNumeric(string plainText)
1136
1137
#else
1137
1138
var dec = int . Parse ( plainText . Substring ( i , 3 ) , NumberStyles . None , CultureInfo . InvariantCulture ) ;
1138
1139
#endif
1139
- DecToBin ( dec , 10 , bitArray , ref index ) ;
1140
+ index = DecToBin ( dec , 10 , bitArray , index ) ;
1140
1141
}
1141
1142
if ( plainText . Length % 3 == 2 )
1142
1143
{
@@ -1145,7 +1146,7 @@ private static BitArray PlainTextToBinaryNumeric(string plainText)
1145
1146
#else
1146
1147
var dec = int . Parse ( plainText . Substring ( plainText . Length / 3 * 3 , 2 ) , NumberStyles . None , CultureInfo . InvariantCulture ) ;
1147
1148
#endif
1148
- DecToBin ( dec , 7 , bitArray , ref index ) ;
1149
+ index = DecToBin ( dec , 7 , bitArray , index ) ;
1149
1150
}
1150
1151
else if ( plainText . Length % 3 == 1 )
1151
1152
{
@@ -1154,7 +1155,7 @@ private static BitArray PlainTextToBinaryNumeric(string plainText)
1154
1155
#else
1155
1156
var dec = int . Parse ( plainText . Substring ( plainText . Length / 3 * 3 , 1 ) , NumberStyles . None , CultureInfo . InvariantCulture ) ;
1156
1157
#endif
1157
- DecToBin ( dec , 4 , bitArray , ref index ) ;
1158
+ index = DecToBin ( dec , 4 , bitArray , index ) ;
1158
1159
}
1159
1160
return bitArray ;
1160
1161
}
@@ -1168,13 +1169,13 @@ private static BitArray PlainTextToBinaryAlphanumeric(string plainText)
1168
1169
while ( count >= 2 )
1169
1170
{
1170
1171
var dec = alphanumEncDict [ plainText [ index ++ ] ] * 45 + alphanumEncDict [ plainText [ index ++ ] ] ;
1171
- DecToBin ( dec , 11 , codeText , ref codeIndex ) ;
1172
+ codeIndex = DecToBin ( dec , 11 , codeText , codeIndex ) ;
1172
1173
count -= 2 ;
1173
1174
1174
1175
}
1175
1176
if ( count > 0 )
1176
1177
{
1177
- DecToBin ( alphanumEncDict [ plainText [ index ] ] , 6 , codeText , ref codeIndex ) ;
1178
+ DecToBin ( alphanumEncDict [ plainText [ index ] ] , 6 , codeText , codeIndex ) ;
1178
1179
}
1179
1180
return codeText ;
1180
1181
}
0 commit comments