Skip to content

Commit 20c9ce6

Browse files
committed
Use unsigned right shift directly from C# 11.
1 parent d5fec16 commit 20c9ce6

File tree

3 files changed

+12
-43
lines changed

3 files changed

+12
-43
lines changed

src/FirebirdSql.Data.FirebirdClient/Common/BitHelpers.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/FirebirdSql.Data.FirebirdClient/Common/DecimalCodec.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
using System;
1919
using System.Diagnostics;
2020
using FirebirdSql.Data.Types;
21-
using static FirebirdSql.Data.Common.BitHelpers;
2221

2322
namespace FirebirdSql.Data.Common;
2423

@@ -107,7 +106,7 @@ public FbDecFloat ParseBytes(byte[] decBytes)
107106
_decimalFormat.ValidateByteLength(decBytes);
108107

109108
var firstByte = decBytes[0] & 0xff;
110-
var signum = -1 * UnsignedRightShift(firstByte, 7) | 1;
109+
var signum = -1 * (firstByte >>> 7) | 1;
111110
var decimalType = DecimalTypeFromFirstByte(firstByte);
112111
switch (decimalType)
113112
{
@@ -124,13 +123,13 @@ public FbDecFloat ParseBytes(byte[] decBytes)
124123
int firstDigit;
125124
if ((firstByte & Combination2) != Combination2)
126125
{
127-
exponentMSB = UnsignedRightShift(firstByte, 3) & 0b01100 | (firstByte & 0b011);
128-
firstDigit = UnsignedRightShift(firstByte, 2) & 0b0111;
126+
exponentMSB = (firstByte >>> 3) & 0b01100 | (firstByte & 0b011);
127+
firstDigit = (firstByte >>> 2) & 0b0111;
129128
}
130129
else
131130
{
132-
exponentMSB = UnsignedRightShift(firstByte, 1) & 0b01100 | (firstByte & 0b011);
133-
firstDigit = 0b01000 | (UnsignedRightShift(firstByte, 2) & 0b01);
131+
exponentMSB = (firstByte >>> 1) & 0b01100 | (firstByte & 0b011);
132+
firstDigit = 0b01000 | ((firstByte >>> 2) & 0b01);
134133
}
135134
var exponentBitsRemaining = _decimalFormat.ExponentContinuationBits - 2;
136135
Debug.Assert(exponentBitsRemaining == _decimalFormat.FormatBitLength - 8 - _decimalFormat.CoefficientContinuationBits, $"Unexpected exponent remaining length {exponentBitsRemaining}.");
@@ -175,8 +174,8 @@ void EncodeFinite(FbDecFloat @decimal, byte[] decBytes)
175174
var biasedExponent = _decimalFormat.BiasedExponent(@decimal.Exponent);
176175
var coefficient = @decimal.Coefficient;
177176
var mostSignificantDigit = _coefficientCoder.EncodeValue(coefficient, decBytes);
178-
var expMSB = UnsignedRightShift(biasedExponent, _decimalFormat.ExponentContinuationBits);
179-
var expTwoBitCont = UnsignedRightShift(biasedExponent, _decimalFormat.ExponentContinuationBits - 2) & 0b011;
177+
var expMSB = biasedExponent >>> _decimalFormat.ExponentContinuationBits;
178+
var expTwoBitCont = (biasedExponent >>> _decimalFormat.ExponentContinuationBits - 2) & 0b011;
180179
if (mostSignificantDigit <= 7)
181180
{
182181
decBytes[0] |= (byte)((expMSB << 5)
@@ -198,7 +197,7 @@ static void EncodeExponentContinuation(byte[] decBytes, int expAndBias, int expB
198197
var expByteIndex = 1;
199198
while (expBitsRemaining > 8)
200199
{
201-
decBytes[expByteIndex++] = (byte)UnsignedRightShift(expAndBias, expBitsRemaining - 8);
200+
decBytes[expByteIndex++] = (byte)(expAndBias >>> expBitsRemaining - 8);
202201
expBitsRemaining -= 8;
203202
}
204203
if (expBitsRemaining > 0)
@@ -219,7 +218,8 @@ static int DecodeExponent(byte[] decBytes, int exponentMSB, int exponentBitsRema
219218
}
220219
if (exponentBitsRemaining > 0)
221220
{
222-
exponent = (exponent << exponentBitsRemaining) | (UnsignedRightShift(decBytes[byteIndex] & 0xFF, 8 - exponentBitsRemaining));
221+
exponent = (exponent << exponentBitsRemaining)
222+
| ((decBytes[byteIndex] & 0xFF) >>> (8 - exponentBitsRemaining));
223223
}
224224
return exponent;
225225
}

src/FirebirdSql.Data.FirebirdClient/Common/DenselyPackedDecimalCodec.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
using System;
1919
using System.Diagnostics;
2020
using System.Numerics;
21-
using static FirebirdSql.Data.Common.BitHelpers;
2221

2322
namespace FirebirdSql.Data.Common;
2423

@@ -309,7 +308,7 @@ BigInteger DecodeValue0(int signum, int firstDigit, byte[] decBytes, int lsbInde
309308
var firstByteIndex = lsbIndex - digitBitsFromEnd / BitPerByte;
310309

311310
var dpdGroupBits = 0x3FF & (
312-
UnsignedRightShift((decBytes[firstByteIndex] & 0xFF), firstByteBitOffset)
311+
(decBytes[firstByteIndex] & 0xFF) >>> firstByteBitOffset
313312
| decBytes[firstByteIndex - 1] << BitPerByte - firstByteBitOffset);
314313

315314
if (dpdGroupBits != 0)
@@ -343,7 +342,7 @@ int EncodeValue0(BigInteger value, byte[] decBytes, int lsbIndex)
343342
decBytes[firstByteIndex] =
344343
(byte)(decBytes[firstByteIndex] | (currentGroup << firstByteBitOffset));
345344
decBytes[firstByteIndex - 1] =
346-
(byte)(decBytes[firstByteIndex - 1] | UnsignedRightShift(currentGroup, BitPerByte - firstByteBitOffset));
345+
(byte)(decBytes[firstByteIndex - 1] | (currentGroup >>> BitPerByte - firstByteBitOffset));
347346
}
348347
var mostSignificantDigit = (int)remainingValue;
349348
Debug.Assert(0 <= mostSignificantDigit && mostSignificantDigit <= 9, $"{nameof(mostSignificantDigit)} out of range, was {mostSignificantDigit}.");

0 commit comments

Comments
 (0)