Skip to content

Commit 957ee98

Browse files
committed
Fixed warnings from CI
1 parent 9b7e41f commit 957ee98

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

src/ImageSharp/Common/Helpers/HexConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ internal static class HexConverter
1616
/// <returns>The number of bytes written to <paramref name="bytes"/>.</returns>
1717
public static int HexStringToBytes(ReadOnlySpan<char> chars, Span<byte> bytes)
1818
{
19-
if ((chars.Length & 1) != 0) // bit-hack for % 2
19+
if ((chars.Length & 1 /* bit-hack for % 2 */) != 0)
2020
{
2121
throw new ArgumentException("Input string length must be a multiple of 2", nameof(chars));
2222
}
2323

24-
if ((bytes.Length << 1) < chars.Length) // bit-hack for * 2
24+
if ((bytes.Length << 1 /* bit-hack for * 2 */) < chars.Length)
2525
{
2626
throw new ArgumentException("Output span must be at least half the length of the input string");
2727
}

src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder
5353

5454
private ArithmeticDecodingTable[] acDecodingTables;
5555

56-
// Use C#'s optimization to refer to assembly's data segment, no allocation occurs.
57-
private ReadOnlySpan<byte> fixedBin => new byte[] { 113, 0, 0, 0 };
58-
5956
private readonly CancellationToken cancellationToken;
6057

6158
private static readonly int[] ArithmeticTable =
@@ -232,7 +229,13 @@ public void InitDecodingTables(List<ArithmeticDecodingTable> arithmeticDecodingT
232229
}
233230
}
234231

235-
private ref byte GetFixedBinReference() => ref MemoryMarshal.GetReference(fixedBin);
232+
private static ref byte GetFixedBinReference()
233+
{
234+
// This uses C#'s optimization to refer to the static data segment of the assembly.
235+
// No allocation occurs.
236+
ReadOnlySpan<byte> fixedBin = new byte[] { 113, 0, 0, 0 };
237+
return ref MemoryMarshal.GetReference(fixedBin);
238+
}
236239

237240
/// <summary>
238241
/// Decodes the entropy coded data.
@@ -776,7 +779,7 @@ private void DecodeBlockProgressiveDc(ArithmeticDecodingComponent component, ref
776779
else
777780
{
778781
// Refinement scan.
779-
ref byte st = ref this.GetFixedBinReference();
782+
ref byte st = ref GetFixedBinReference();
780783

781784
blockDataRef |= (short)(this.DecodeBinaryDecision(ref reader, ref st) << this.SuccessiveLow);
782785
}
@@ -822,7 +825,7 @@ private void DecodeBlockProgressiveAc(ArithmeticDecodingComponent component, ref
822825

823826
// Figure F.21: Decoding nonzero value v.
824827
// Figure F.22: Decoding the sign of v.
825-
int sign = this.DecodeBinaryDecision(ref reader, ref this.GetFixedBinReference());
828+
int sign = this.DecodeBinaryDecision(ref reader, ref GetFixedBinReference());
826829
st = ref Unsafe.Add(ref st, 2);
827830

828831
// Figure F.23: Decoding the magnitude category of v.
@@ -918,7 +921,7 @@ private void ReadBlockProgressiveAcRefined(ArithmeticStatistics acStatistics, re
918921

919922
if (this.DecodeBinaryDecision(ref reader, ref Unsafe.Add(ref st, 1)) != 0)
920923
{
921-
bool flag = this.DecodeBinaryDecision(ref reader, ref this.GetFixedBinReference()) != 0;
924+
bool flag = this.DecodeBinaryDecision(ref reader, ref GetFixedBinReference()) != 0;
922925
coef = (short)(coef + (flag ? m1 : p1));
923926

924927
break;
@@ -1048,7 +1051,7 @@ private void DecodeBlockBaseline(
10481051

10491052
// Figure F.21: Decoding nonzero value v.
10501053
// Figure F.22: Decoding the sign of v.
1051-
int sign = this.DecodeBinaryDecision(ref reader, ref this.GetFixedBinReference());
1054+
int sign = this.DecodeBinaryDecision(ref reader, ref GetFixedBinReference());
10521055
st = ref Unsafe.Add(ref st, 2);
10531056

10541057
// Figure F.23: Decoding the magnitude category of v.

src/ImageSharp/Formats/Webp/AlphaDecoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ private static void VerticalUnfilter(Span<byte> prev, Span<byte> input, Span<byt
376376
Unsafe.As<byte, Vector256<byte>>(ref outputRef) = c0;
377377
}
378378

379-
for (; i < (uint) width; i++)
379+
for (; i < (uint)width; i++)
380380
{
381381
dst[(int)i] = (byte)(prev[(int)i] + input[(int)i]);
382382
}

src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,7 @@ public static void VFilter16(Span<byte> p, int offset, int stride, int thresh, i
15531553
Unsafe.As<byte, Vector128<int>>(ref Unsafe.Add(ref outputRef, (uint)(offset - (3 * stride)))) = p2.AsInt32();
15541554
Unsafe.As<byte, Vector128<int>>(ref Unsafe.Add(ref outputRef, (uint)(offset - (2 * stride)))) = p1.AsInt32();
15551555
Unsafe.As<byte, Vector128<int>>(ref Unsafe.Add(ref outputRef, (uint)(offset - stride))) = p0.AsInt32();
1556-
Unsafe.As<byte, Vector128<int>>(ref Unsafe.Add(ref outputRef, (uint)(offset))) = q0.AsInt32();
1556+
Unsafe.As<byte, Vector128<int>>(ref Unsafe.Add(ref outputRef, (uint)offset)) = q0.AsInt32();
15571557
Unsafe.As<byte, Vector128<int>>(ref Unsafe.Add(ref outputRef, (uint)(offset + stride))) = q1.AsInt32();
15581558
Unsafe.As<byte, Vector128<int>>(ref Unsafe.Add(ref outputRef, (uint)(offset + (2 * stride)))) = q2.AsInt32();
15591559
}
@@ -1599,7 +1599,7 @@ public static void VFilter16i(Span<byte> p, int offset, int stride, int thresh,
15991599
if (Sse2.IsSupported)
16001600
{
16011601
ref byte pRef = ref MemoryMarshal.GetReference(p);
1602-
Vector128<byte> p3 = Unsafe.As<byte, Vector128<byte>>(ref Unsafe.Add(ref pRef, (uint)(offset)));
1602+
Vector128<byte> p3 = Unsafe.As<byte, Vector128<byte>>(ref Unsafe.Add(ref pRef, (uint)offset));
16031603
Vector128<byte> p2 = Unsafe.As<byte, Vector128<byte>>(ref Unsafe.Add(ref pRef, (uint)(offset + stride)));
16041604
Vector128<byte> p1 = Unsafe.As<byte, Vector128<byte>>(ref Unsafe.Add(ref pRef, (uint)(offset + (2 * stride))));
16051605
Vector128<byte> p0 = Unsafe.As<byte, Vector128<byte>>(ref Unsafe.Add(ref pRef, (uint)(offset + (3 * stride))));

0 commit comments

Comments
 (0)