Skip to content

Commit

Permalink
Write 2 values once
Browse files Browse the repository at this point in the history
  • Loading branch information
buyaa-n committed Jul 3, 2024
1 parent 23b8c61 commit 8f42dae
Showing 1 changed file with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,19 @@ public unsafe void EncodeOneOptionallyPadTwo(byte* oneByte, byte* dest, ref byte
byte i0 = Unsafe.Add(ref encodingMap, (IntPtr)(i >> 10));
byte i1 = Unsafe.Add(ref encodingMap, (IntPtr)((i >> 4) & 0x3F));

ushort result;

if (BitConverter.IsLittleEndian)
{
result = (ushort)(i0 | (i1 << 8));
}
else
{
result = (ushort)((i0 << 8) | i1);
}

Unsafe.WriteUnaligned(dest, result);

dest[0] = i0;
dest[1] = i1;
}
Expand Down Expand Up @@ -331,11 +344,21 @@ public unsafe void EncodeOneOptionallyPadTwo(byte* oneByte, ushort* dest, ref by

uint i = t0 << 8;

ushort i0 = Unsafe.Add(ref encodingMap, (IntPtr)(i >> 10));
ushort i1 = Unsafe.Add(ref encodingMap, (IntPtr)((i >> 4) & 0x3F));
uint i0 = Unsafe.Add(ref encodingMap, (IntPtr)(i >> 10));
uint i1 = Unsafe.Add(ref encodingMap, (IntPtr)((i >> 4) & 0x3F));

dest[0] = i0;
dest[1] = i1;
uint result;

if (BitConverter.IsLittleEndian)
{
result = (i0 | (i1 << 16));
}
else
{
result = ((i0 << 16) | i1);
}

Unsafe.WriteUnaligned(dest, result);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down

0 comments on commit 8f42dae

Please sign in to comment.