Skip to content

Commit 2a41577

Browse files
committed
Astc BitTransferSigned use ref instead of pointer
1 parent b3371b3 commit 2a41577

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

AssetRipper.TextureDecoder/Astc/AstcDecoder.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ private unsafe static void DecodeEndpoints(ReadOnlySpan<byte> input, ref BlockDa
240240
Span<IntSeqData> epSeq = stackalloc IntSeqData[32];
241241
DecodeIntseq(input, pBlock.part_num == 1 ? 17 : 29, CemTableA[pBlock.cem_range], CemTableB[pBlock.cem_range], pBlock.endpoint_value_num, false, epSeq);
242242

243-
int* ev = stackalloc int[32];
243+
Span<int> ev = stackalloc int[32];
244244
switch (CemTableA[pBlock.cem_range])
245245
{
246246
case 3:
@@ -355,8 +355,8 @@ private unsafe static void DecodeEndpoints(ReadOnlySpan<byte> input, ref BlockDa
355355
break;
356356
}
357357

358-
int* v = ev;
359-
for (int cem = 0, cemOff = 0; cem < pBlock.part_num; v += (pBlock.cem[cem] / 4 + 1) * 2, cem++, cemOff += 8)
358+
Span<int> v = ev;
359+
for (int cem = 0, cemOff = 0; cem < pBlock.part_num; v = v.Slice((pBlock.cem[cem] / 4 + 1) * 2), cem++, cemOff += 8)
360360
{
361361
switch (pBlock.cem[cem])
362362
{
@@ -383,8 +383,8 @@ private unsafe static void DecodeEndpoints(ReadOnlySpan<byte> input, ref BlockDa
383383
}
384384
break;
385385
case 5:
386-
BitTransferSigned(&v[1], &v[0]);
387-
BitTransferSigned(&v[3], &v[2]);
386+
BitTransferSigned(ref v[1], ref v[0]);
387+
BitTransferSigned(ref v[3], ref v[2]);
388388
v[1] += v[0];
389389
fixed (int* endpoint = &pBlock.endpoints[cemOff])
390390
{
@@ -415,9 +415,9 @@ private unsafe static void DecodeEndpoints(ReadOnlySpan<byte> input, ref BlockDa
415415

416416
break;
417417
case 9:
418-
BitTransferSigned(&v[1], &v[0]);
419-
BitTransferSigned(&v[3], &v[2]);
420-
BitTransferSigned(&v[5], &v[4]);
418+
BitTransferSigned(ref v[1], ref v[0]);
419+
BitTransferSigned(ref v[3], ref v[2]);
420+
BitTransferSigned(ref v[5], ref v[4]);
421421
if (v[1] + v[3] + v[5] >= 0)
422422
{
423423
fixed (int* endpoint = &pBlock.endpoints[cemOff])
@@ -458,10 +458,10 @@ private unsafe static void DecodeEndpoints(ReadOnlySpan<byte> input, ref BlockDa
458458

459459
break;
460460
case 13:
461-
BitTransferSigned(&v[1], &v[0]);
462-
BitTransferSigned(&v[3], &v[2]);
463-
BitTransferSigned(&v[5], &v[4]);
464-
BitTransferSigned(&v[7], &v[6]);
461+
BitTransferSigned(ref v[1], ref v[0]);
462+
BitTransferSigned(ref v[3], ref v[2]);
463+
BitTransferSigned(ref v[5], ref v[4]);
464+
BitTransferSigned(ref v[7], ref v[6]);
465465
if (v[1] + v[3] + v[5] >= 0)
466466
{
467467
fixed (int* endpoint = &pBlock.endpoints[cemOff])
@@ -965,13 +965,13 @@ private static byte Clamp(int n)
965965
}
966966

967967
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
968-
private static unsafe void BitTransferSigned(int* a, int* b)
968+
private static void BitTransferSigned(ref int a, ref int b)
969969
{
970-
*b = (*b >> 1) | (*a & 0x80);
971-
*a = (*a >> 1) & 0x3f;
972-
if ((*a & 0x20) != 0)
970+
b = (b >> 1) | (a & 0x80);
971+
a = (a >> 1) & 0x3f;
972+
if ((a & 0x20) != 0)
973973
{
974-
*a -= 0x40;
974+
a -= 0x40;
975975
}
976976
}
977977

0 commit comments

Comments
 (0)