Skip to content

Commit 4b398e6

Browse files
committed
Use collection expressions
1 parent a25a42d commit 4b398e6

2 files changed

Lines changed: 30 additions & 28 deletions

File tree

AssetRipper.TextureDecoder/Astc/AstcDecoder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,11 +621,11 @@ private static void SelectPartition(ReadOnlySpan<byte> input, ref BlockData bloc
621621
}
622622

623623

624-
ReadOnlySpan<int> sh = stackalloc int[2]
625-
{
624+
ReadOnlySpan<int> sh =
625+
[
626626
(seed & 2) != 0 ? 4 : 5,
627627
block.part_num == 3 ? 6 : 5
628-
};
628+
];
629629

630630
if ((seed & 1) != 0)
631631
{
@@ -678,7 +678,7 @@ private static void ApplicateColor(BlockData block, Span<uint> output)
678678
{
679679
if (block.dual_plane != 0)
680680
{
681-
Span<int> ps = stackalloc int[] { 0, 0, 0, 0 };
681+
Span<int> ps = [0, 0, 0, 0];
682682
ps[block.plane_selector] = 1;
683683
if (block.part_num > 1)
684684
{

AssetRipper.TextureDecoder/Etc/EtcDecoder.cs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -410,11 +410,11 @@ private unsafe static int DecompressEACRGSigned(ReadOnlySpan<byte> input, int wi
410410
private static void DecodeEtc1Block(ReadOnlySpan<byte> input, Span<uint> output)
411411
{
412412
byte i3 = input[3];
413-
ReadOnlySpan<int> code = stackalloc int[2]
414-
{
413+
ReadOnlySpan<int> code =
414+
[
415415
(i3 >> 5) * 4,
416416
(i3 >> 2 & 7) * 4
417-
};
417+
];
418418
Span<byte> c = stackalloc byte[6];
419419
int ti = (i3 & 1) * 16;
420420
if ((i3 & 2) != 0)
@@ -486,13 +486,13 @@ private static void DecodeEtc2Block(ReadOnlySpan<byte> input, Span<uint> output)
486486
}
487487
int ti = input[3] >> 1 & 6 | input[3] & 1;
488488
byte d = Etc2DistanceTable[ti];
489-
ReadOnlySpan<uint> color_set = stackalloc uint[]
490-
{
489+
ReadOnlySpan<uint> color_set =
490+
[
491491
ApplicateColorRaw(c, 0),
492492
ApplicateColor(c, 1, d),
493493
ApplicateColorRaw(c, 1),
494494
ApplicateColor(c, 1, -d)
495-
};
495+
];
496496

497497
for (int i = 0; i < 16; i++, j >>= 1, k >>= 1)
498498
{
@@ -527,13 +527,13 @@ private static void DecodeEtc2Block(ReadOnlySpan<byte> input, Span<uint> output)
527527
++di;
528528
}
529529
byte d = Etc2DistanceTable[di];
530-
ReadOnlySpan<uint> color_set = stackalloc uint[]
531-
{
530+
ReadOnlySpan<uint> color_set =
531+
[
532532
ApplicateColor(c, 0, d),
533533
ApplicateColor(c, 0, -d),
534534
ApplicateColor(c, 1, d),
535535
ApplicateColor(c, 1, -d)
536-
};
536+
];
537537
for (int i = 0; i < 16; i++, j >>= 1, k >>= 1)
538538
{
539539
int index = k << 1 & 2 | j & 1;
@@ -577,9 +577,11 @@ private static void DecodeEtc2Block(ReadOnlySpan<byte> input, Span<uint> output)
577577
else
578578
{
579579
// differential
580-
Span<int> code = stackalloc int[2];
581-
code[0] = (input[3] >> 5) * 4;
582-
code[1] = (input[3] >> 2 & 7) * 4;
580+
ReadOnlySpan<int> code =
581+
[
582+
(input[3] >> 5) * 4,
583+
(input[3] >> 2 & 7) * 4
584+
];
583585
int ti = (input[3] & 1) * 16;
584586
unchecked
585587
{
@@ -610,11 +612,11 @@ private static void DecodeEtc2Block(ReadOnlySpan<byte> input, Span<uint> output)
610612
else
611613
{
612614
// individual
613-
ReadOnlySpan<int> code = stackalloc int[2]
614-
{
615+
ReadOnlySpan<int> code =
616+
[
615617
(input[3] >> 5) * 4,
616618
(input[3] >> 2 & 7) * 4
617-
};
619+
];
618620
int ti = (input[3] & 1) * 16;
619621
unchecked
620622
{
@@ -673,13 +675,13 @@ private static void DecodeEtc2PunchThrowBlock(ReadOnlySpan<byte> input, Span<uin
673675
}
674676
int ti = input[3] >> 1 & 6 | input[3] & 1;
675677
byte d = Etc2DistanceTable[ti];
676-
ReadOnlySpan<uint> color_set = stackalloc uint[4]
677-
{
678+
ReadOnlySpan<uint> color_set =
679+
[
678680
ApplicateColorRaw(c, 0),
679681
ApplicateColor(c, 1, d),
680682
ApplicateColorRaw(c, 1),
681683
ApplicateColor(c, 1, -d)
682-
};
684+
];
683685

684686
for (int i = 0; i < 16; i++, j >>= 1, k >>= 1)
685687
{
@@ -715,13 +717,13 @@ private static void DecodeEtc2PunchThrowBlock(ReadOnlySpan<byte> input, Span<uin
715717
++di;
716718
}
717719
byte d = Etc2DistanceTable[di];
718-
ReadOnlySpan<uint> color_set = stackalloc uint[4]
719-
{
720+
ReadOnlySpan<uint> color_set =
721+
[
720722
ApplicateColor(c, 0, d),
721723
ApplicateColor(c, 0, -d),
722724
ApplicateColor(c, 1, d),
723725
ApplicateColor(c, 1, -d)
724-
};
726+
];
725727
for (int i = 0; i < 16; i++, j >>= 1, k >>= 1)
726728
{
727729
int index = k << 1 & 2 | j & 1;
@@ -766,11 +768,11 @@ private static void DecodeEtc2PunchThrowBlock(ReadOnlySpan<byte> input, Span<uin
766768
else
767769
{
768770
// differential (Etc1Block + mask + specific mod table)
769-
ReadOnlySpan<int> code = stackalloc int[2]
770-
{
771+
ReadOnlySpan<int> code =
772+
[
771773
(input[3] >> 5) * 4,
772774
(input[3] >> 2 & 7) * 4
773-
};
775+
];
774776
int ti = (input[3] & 1) * 16;
775777
unchecked
776778
{

0 commit comments

Comments
 (0)