Skip to content

Commit

Permalink
Address PR feedback for pre-existing code
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub committed May 17, 2023
1 parent d1b14a2 commit b4819fd
Showing 1 changed file with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,10 @@ private static unsafe OperationStatus DecodeFromUtf8InPlace(Span<byte> buffer, o
uint destIndex = 0;

// only decode input if it is a multiple of 4
if (bufferLength != ((bufferLength >> 2) * 4))
if (bufferLength % 4 != 0)
{
goto InvalidExit;
}
if (bufferLength == 0)
{
goto DoneExit;
}

ref sbyte decodingMap = ref MemoryMarshal.GetReference(DecodingMap);

Expand All @@ -387,8 +383,8 @@ private static unsafe OperationStatus DecodeFromUtf8InPlace(Span<byte> buffer, o
uint t2 = bufferBytes[bufferLength - 2];
uint t3 = bufferBytes[bufferLength - 1];

int i0 = Unsafe.Add(ref decodingMap, (IntPtr)t0);
int i1 = Unsafe.Add(ref decodingMap, (IntPtr)t1);
int i0 = Unsafe.Add(ref decodingMap, t0);
int i1 = Unsafe.Add(ref decodingMap, t1);

i0 <<= 18;
i1 <<= 12;
Expand All @@ -397,8 +393,8 @@ private static unsafe OperationStatus DecodeFromUtf8InPlace(Span<byte> buffer, o

if (t3 != EncodingPad)
{
int i2 = Unsafe.Add(ref decodingMap, (IntPtr)t2);
int i3 = Unsafe.Add(ref decodingMap, (IntPtr)t3);
int i2 = Unsafe.Add(ref decodingMap, t2);
int i3 = Unsafe.Add(ref decodingMap, t3);

i2 <<= 6;

Expand All @@ -415,7 +411,7 @@ private static unsafe OperationStatus DecodeFromUtf8InPlace(Span<byte> buffer, o
}
else if (t2 != EncodingPad)
{
int i2 = Unsafe.Add(ref decodingMap, (IntPtr)t2);
int i2 = Unsafe.Add(ref decodingMap, t2);

i2 <<= 6;

Expand All @@ -441,7 +437,6 @@ private static unsafe OperationStatus DecodeFromUtf8InPlace(Span<byte> buffer, o
destIndex += 1;
}

DoneExit:
bytesWritten = (int)destIndex;
return OperationStatus.Done;

Expand Down Expand Up @@ -949,10 +944,10 @@ private static unsafe int Decode(byte* encodedBytes, ref sbyte decodingMap)
uint t2 = encodedBytes[2];
uint t3 = encodedBytes[3];

int i0 = Unsafe.Add(ref decodingMap, (IntPtr)t0);
int i1 = Unsafe.Add(ref decodingMap, (IntPtr)t1);
int i2 = Unsafe.Add(ref decodingMap, (IntPtr)t2);
int i3 = Unsafe.Add(ref decodingMap, (IntPtr)t3);
int i0 = Unsafe.Add(ref decodingMap, t0);
int i1 = Unsafe.Add(ref decodingMap, t1);
int i2 = Unsafe.Add(ref decodingMap, t2);
int i3 = Unsafe.Add(ref decodingMap, t3);

i0 <<= 18;
i1 <<= 12;
Expand Down

0 comments on commit b4819fd

Please sign in to comment.