Skip to content

Commit 95b56d3

Browse files
committed
Use explicit types instead of var
1 parent a6b4d82 commit 95b56d3

File tree

271 files changed

+1550
-1549
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

271 files changed

+1550
-1549
lines changed

src/ImageSharp/Advanced/ParallelRowIterator.Wrappers.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void Invoke(int i)
139139
}
140140

141141
int yMax = Math.Min(yMin + this.stepY, this.maxY);
142-
var rows = new RowInterval(yMin, yMax);
142+
RowInterval rows = new RowInterval(yMin, yMax);
143143

144144
// Skip the safety copy when invoking a potentially impure method on a readonly field
145145
Unsafe.AsRef(in this.operation).Invoke(in rows);
@@ -185,7 +185,7 @@ public void Invoke(int i)
185185
}
186186

187187
int yMax = Math.Min(yMin + this.stepY, this.maxY);
188-
var rows = new RowInterval(yMin, yMax);
188+
RowInterval rows = new RowInterval(yMin, yMax);
189189

190190
using IMemoryOwner<TBuffer> buffer = this.allocator.Allocate<TBuffer>(this.bufferLength);
191191

src/ImageSharp/Advanced/ParallelRowIterator.cs

+14-14
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static partial class ParallelRowIterator
2626
public static void IterateRows<T>(Configuration configuration, Rectangle rectangle, in T operation)
2727
where T : struct, IRowOperation
2828
{
29-
var parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
29+
ParallelExecutionSettings parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
3030
IterateRows(rectangle, in parallelSettings, in operation);
3131
}
3232

@@ -65,8 +65,8 @@ public static void IterateRows<T>(
6565
}
6666

6767
int verticalStep = DivideCeil(rectangle.Height, numOfSteps);
68-
var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps };
69-
var wrappingOperation = new RowOperationWrapper<T>(top, bottom, verticalStep, in operation);
68+
ParallelOptions? parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps };
69+
RowOperationWrapper<T> wrappingOperation = new RowOperationWrapper<T>(top, bottom, verticalStep, in operation);
7070

7171
Parallel.For(
7272
0,
@@ -88,7 +88,7 @@ public static void IterateRows<T, TBuffer>(Configuration configuration, Rectangl
8888
where T : struct, IRowOperation<TBuffer>
8989
where TBuffer : unmanaged
9090
{
91-
var parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
91+
ParallelExecutionSettings parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
9292
IterateRows<T, TBuffer>(rectangle, in parallelSettings, in operation);
9393
}
9494

@@ -135,8 +135,8 @@ public static void IterateRows<T, TBuffer>(
135135
}
136136

137137
int verticalStep = DivideCeil(height, numOfSteps);
138-
var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps };
139-
var wrappingOperation = new RowOperationWrapper<T, TBuffer>(top, bottom, verticalStep, bufferLength, allocator, in operation);
138+
ParallelOptions? parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps };
139+
RowOperationWrapper<T, TBuffer> wrappingOperation = new RowOperationWrapper<T, TBuffer>(top, bottom, verticalStep, bufferLength, allocator, in operation);
140140

141141
Parallel.For(
142142
0,
@@ -156,7 +156,7 @@ public static void IterateRows<T, TBuffer>(
156156
public static void IterateRowIntervals<T>(Configuration configuration, Rectangle rectangle, in T operation)
157157
where T : struct, IRowIntervalOperation
158158
{
159-
var parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
159+
ParallelExecutionSettings parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
160160
IterateRowIntervals(rectangle, in parallelSettings, in operation);
161161
}
162162

@@ -186,14 +186,14 @@ public static void IterateRowIntervals<T>(
186186
// Avoid TPL overhead in this trivial case:
187187
if (numOfSteps == 1)
188188
{
189-
var rows = new RowInterval(top, bottom);
189+
RowInterval rows = new RowInterval(top, bottom);
190190
Unsafe.AsRef(in operation).Invoke(in rows);
191191
return;
192192
}
193193

194194
int verticalStep = DivideCeil(rectangle.Height, numOfSteps);
195-
var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps };
196-
var wrappingOperation = new RowIntervalOperationWrapper<T>(top, bottom, verticalStep, in operation);
195+
ParallelOptions? parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps };
196+
RowIntervalOperationWrapper<T> wrappingOperation = new RowIntervalOperationWrapper<T>(top, bottom, verticalStep, in operation);
197197

198198
Parallel.For(
199199
0,
@@ -215,7 +215,7 @@ public static void IterateRowIntervals<T, TBuffer>(Configuration configuration,
215215
where T : struct, IRowIntervalOperation<TBuffer>
216216
where TBuffer : unmanaged
217217
{
218-
var parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
218+
ParallelExecutionSettings parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
219219
IterateRowIntervals<T, TBuffer>(rectangle, in parallelSettings, in operation);
220220
}
221221

@@ -250,7 +250,7 @@ public static void IterateRowIntervals<T, TBuffer>(
250250
// Avoid TPL overhead in this trivial case:
251251
if (numOfSteps == 1)
252252
{
253-
var rows = new RowInterval(top, bottom);
253+
RowInterval rows = new RowInterval(top, bottom);
254254
using IMemoryOwner<TBuffer> buffer = allocator.Allocate<TBuffer>(bufferLength);
255255

256256
Unsafe.AsRef(in operation).Invoke(in rows, buffer.Memory.Span);
@@ -259,8 +259,8 @@ public static void IterateRowIntervals<T, TBuffer>(
259259
}
260260

261261
int verticalStep = DivideCeil(height, numOfSteps);
262-
var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps };
263-
var wrappingOperation = new RowIntervalOperationWrapper<T, TBuffer>(top, bottom, verticalStep, bufferLength, allocator, in operation);
262+
ParallelOptions? parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps };
263+
RowIntervalOperationWrapper<T, TBuffer> wrappingOperation = new RowIntervalOperationWrapper<T, TBuffer>(top, bottom, verticalStep, bufferLength, allocator, in operation);
264264

265265
Parallel.For(
266266
0,

src/ImageSharp/Common/Helpers/Numerics.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,8 @@ private static void ClampImpl<T>(Span<T> span, T min, T max)
470470
where T : unmanaged
471471
{
472472
ref T sRef = ref MemoryMarshal.GetReference(span);
473-
var vmin = new Vector<T>(min);
474-
var vmax = new Vector<T>(max);
473+
Vector<T> vmin = new Vector<T>(min);
474+
Vector<T> vmax = new Vector<T>(max);
475475

476476
nint n = (nint)(uint)span.Length / Vector<T>.Count;
477477
nint m = Modulo4(n);
@@ -726,12 +726,12 @@ public static unsafe void CubeRootOnXYZ(Span<Vector4> vectors)
726726
ref Vector128<float> vectors128Ref = ref Unsafe.As<Vector4, Vector128<float>>(ref MemoryMarshal.GetReference(vectors));
727727
ref Vector128<float> vectors128End = ref Unsafe.Add(ref vectors128Ref, (uint)vectors.Length);
728728

729-
var v128_341 = Vector128.Create(341);
729+
Vector128<int> v128_341 = Vector128.Create(341);
730730
Vector128<int> v128_negativeZero = Vector128.Create(-0.0f).AsInt32();
731731
Vector128<int> v128_one = Vector128.Create(1.0f).AsInt32();
732732

733-
var v128_13rd = Vector128.Create(1 / 3f);
734-
var v128_23rds = Vector128.Create(2 / 3f);
733+
Vector128<float> v128_13rd = Vector128.Create(1 / 3f);
734+
Vector128<float> v128_23rds = Vector128.Create(2 / 3f);
735735

736736
while (Unsafe.IsAddressLessThan(ref vectors128Ref, ref vectors128End))
737737
{

src/ImageSharp/Common/Helpers/SimdUtils.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ internal static Vector<float> FastRound(this Vector<float> v)
5353
}
5454
else
5555
{
56-
var magic0 = new Vector<int>(int.MinValue); // 0x80000000
57-
var sgn0 = Vector.AsVectorSingle(magic0);
58-
var and0 = Vector.BitwiseAnd(sgn0, v);
59-
var or0 = Vector.BitwiseOr(and0, new Vector<float>(8388608.0f));
60-
var add0 = Vector.Add(v, or0);
56+
Vector<int> magic0 = new Vector<int>(int.MinValue); // 0x80000000
57+
Vector<float> sgn0 = Vector.AsVectorSingle(magic0);
58+
Vector<float> and0 = Vector.BitwiseAnd(sgn0, v);
59+
Vector<float> or0 = Vector.BitwiseOr(and0, new Vector<float>(8388608.0f));
60+
Vector<float> add0 = Vector.Add(v, or0);
6161
return Vector.Subtract(add0, or0);
6262
}
6363
}

src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public void LoadFrom(Span<int> source)
140140
/// <inheritdoc />
141141
public override string ToString()
142142
{
143-
var sb = new StringBuilder();
143+
StringBuilder? sb = new StringBuilder();
144144
sb.Append('[');
145145
for (int i = 0; i < Size; i++)
146146
{

src/ImageSharp/Formats/Jpeg/Components/Block8x8F.ScaledCopy.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ static void WidenCopyRowImpl2x2(ref Vector4 selfBase, ref Vector2 destBase, nuin
5757
ref Vector4 dTopLeft = ref Unsafe.As<Vector2, Vector4>(ref Unsafe.Add(ref destBase, offset));
5858
ref Vector4 dBottomLeft = ref Unsafe.As<Vector2, Vector4>(ref Unsafe.Add(ref destBase, offset + destStride));
5959

60-
var xyLeft = new Vector4(sLeft.X);
60+
Vector4 xyLeft = new Vector4(sLeft.X);
6161
xyLeft.Z = sLeft.Y;
6262
xyLeft.W = sLeft.Y;
6363

64-
var zwLeft = new Vector4(sLeft.Z);
64+
Vector4 zwLeft = new Vector4(sLeft.Z);
6565
zwLeft.Z = sLeft.W;
6666
zwLeft.W = sLeft.W;
6767

68-
var xyRight = new Vector4(sRight.X);
68+
Vector4 xyRight = new Vector4(sRight.X);
6969
xyRight.Z = sRight.Y;
7070
xyRight.W = sRight.Y;
7171

72-
var zwRight = new Vector4(sRight.Z);
72+
Vector4 zwRight = new Vector4(sRight.Z);
7373
zwRight.Z = sRight.W;
7474
zwRight.W = sRight.W;
7575

src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykArm64.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public override void ConvertToRgbInplace(in ComponentValues values)
3030
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component3));
3131

3232
// Used for the color conversion
33-
var scale = Vector128.Create(1 / (this.MaximumValue * this.MaximumValue));
33+
Vector128<float> scale = Vector128.Create(1 / (this.MaximumValue * this.MaximumValue));
3434

3535
nint n = (nint)(uint)values.Component0.Length / Vector128<float>.Count;
3636
for (nint i = 0; i < n; i++)
@@ -69,7 +69,7 @@ public static void ConvertFromRgb(in ComponentValues values, float maxValue, Spa
6969
ref Vector128<float> srcB =
7070
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(bLane));
7171

72-
var scale = Vector128.Create(maxValue);
72+
Vector128<float> scale = Vector128.Create(maxValue);
7373

7474
nint n = (nint)(uint)values.Component0.Length / Vector128<float>.Count;
7575
for (nint i = 0; i < n; i++)

src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public override void ConvertToRgbInplace(in ComponentValues values)
3030
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(values.Component3));
3131

3232
// Used for the color conversion
33-
var scale = Vector256.Create(1 / (this.MaximumValue * this.MaximumValue));
33+
Vector256<float> scale = Vector256.Create(1 / (this.MaximumValue * this.MaximumValue));
3434

3535
nuint n = values.Component0.Vector256Count<float>();
3636
for (nuint i = 0; i < n; i++)
@@ -69,7 +69,7 @@ public static void ConvertFromRgb(in ComponentValues values, float maxValue, Spa
6969
ref Vector256<float> srcB =
7070
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(bLane));
7171

72-
var scale = Vector256.Create(maxValue);
72+
Vector256<float> scale = Vector256.Create(maxValue);
7373

7474
nuint n = values.Component0.Vector256Count<float>();
7575
for (nuint i = 0; i < n; i++)

src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected override void ConvertToRgbInplaceVectorized(in ComponentValues values)
2828
ref Vector<float> kBase =
2929
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component3));
3030

31-
var scale = new Vector<float>(1 / (this.MaximumValue * this.MaximumValue));
31+
Vector<float> scale = new Vector<float>(1 / (this.MaximumValue * this.MaximumValue));
3232

3333
nuint n = values.Component0.VectorCount<float>();
3434
for (nuint i = 0; i < n; i++)
@@ -76,7 +76,7 @@ public static void ConvertFromRgbInplaceVectorized(in ComponentValues values, fl
7676
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(b));
7777

7878
// Used for the color conversion
79-
var scale = new Vector<float>(maxValue);
79+
Vector<float> scale = new Vector<float>(maxValue);
8080

8181
nuint n = values.Component0.VectorCount<float>();
8282
for (nuint i = 0; i < n; i++)
@@ -86,7 +86,7 @@ public static void ConvertFromRgbInplaceVectorized(in ComponentValues values, fl
8686
Vector<float> ytmp = scale - Unsafe.Add(ref srcB, i);
8787
Vector<float> ktmp = Vector.Min(ctmp, Vector.Min(mtmp, ytmp));
8888

89-
var kMask = Vector.Equals(ktmp, scale);
89+
Vector<int> kMask = Vector.Equals(ktmp, scale);
9090
ctmp = Vector.AndNot((ctmp - ktmp) / (scale - ktmp), kMask.As<int, float>());
9191
mtmp = Vector.AndNot((mtmp - ktmp) / (scale - ktmp), kMask.As<int, float>());
9292
ytmp = Vector.AndNot((ytmp - ktmp) / (scale - ktmp), kMask.As<int, float>());

src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleArm.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public override void ConvertToRgbInplace(in ComponentValues values)
2525
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component0));
2626

2727
// Used for the color conversion
28-
var scale = Vector128.Create(1 / this.MaximumValue);
28+
Vector128<float> scale = Vector128.Create(1 / this.MaximumValue);
2929

3030
nuint n = values.Component0.Vector128Count<float>();
3131
for (nuint i = 0; i < n; i++)
@@ -49,9 +49,9 @@ public override void ConvertFromRgb(in ComponentValues values, Span<float> rLane
4949
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(bLane));
5050

5151
// Used for the color conversion
52-
var f0299 = Vector128.Create(0.299f);
53-
var f0587 = Vector128.Create(0.587f);
54-
var f0114 = Vector128.Create(0.114f);
52+
Vector128<float> f0299 = Vector128.Create(0.299f);
53+
Vector128<float> f0587 = Vector128.Create(0.587f);
54+
Vector128<float> f0114 = Vector128.Create(0.114f);
5555

5656
nuint n = values.Component0.Vector128Count<float>();
5757
for (nuint i = 0; i < n; i++)

src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public override void ConvertToRgbInplace(in ComponentValues values)
2525
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(values.Component0));
2626

2727
// Used for the color conversion
28-
var scale = Vector256.Create(1 / this.MaximumValue);
28+
Vector256<float> scale = Vector256.Create(1 / this.MaximumValue);
2929

3030
nuint n = values.Component0.Vector256Count<float>();
3131
for (nuint i = 0; i < n; i++)
@@ -49,9 +49,9 @@ public override void ConvertFromRgb(in ComponentValues values, Span<float> rLane
4949
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(bLane));
5050

5151
// Used for the color conversion
52-
var f0299 = Vector256.Create(0.299f);
53-
var f0587 = Vector256.Create(0.587f);
54-
var f0114 = Vector256.Create(0.114f);
52+
Vector256<float> f0299 = Vector256.Create(0.299f);
53+
Vector256<float> f0587 = Vector256.Create(0.587f);
54+
Vector256<float> f0114 = Vector256.Create(0.114f);
5555

5656
nuint n = values.Component0.Vector256Count<float>();
5757
for (nuint i = 0; i < n; i++)

src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected override void ConvertToRgbInplaceVectorized(in ComponentValues values)
2222
ref Vector<float> cBase =
2323
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component0));
2424

25-
var scale = new Vector<float>(1 / this.MaximumValue);
25+
Vector<float> scale = new Vector<float>(1 / this.MaximumValue);
2626

2727
nuint n = values.Component0.VectorCount<float>();
2828
for (nuint i = 0; i < n; i++)
@@ -49,9 +49,9 @@ protected override void ConvertFromRgbVectorized(in ComponentValues values, Span
4949
ref Vector<float> srcB =
5050
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(bLane));
5151

52-
var rMult = new Vector<float>(0.299f);
53-
var gMult = new Vector<float>(0.587f);
54-
var bMult = new Vector<float>(0.114f);
52+
Vector<float> rMult = new Vector<float>(0.299f);
53+
Vector<float> gMult = new Vector<float>(0.587f);
54+
Vector<float> bMult = new Vector<float>(0.114f);
5555

5656
nuint n = values.Component0.VectorCount<float>();
5757
for (nuint i = 0; i < n; i++)

src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbArm.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public override void ConvertToRgbInplace(in ComponentValues values)
2929
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component2));
3030

3131
// Used for the color conversion
32-
var scale = Vector128.Create(1 / this.MaximumValue);
32+
Vector128<float> scale = Vector128.Create(1 / this.MaximumValue);
3333
nuint n = values.Component0.Vector128Count<float>();
3434
for (nuint i = 0; i < n; i++)
3535
{

src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public override void ConvertToRgbInplace(in ComponentValues values)
2828
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(values.Component2));
2929

3030
// Used for the color conversion
31-
var scale = Vector256.Create(1 / this.MaximumValue);
31+
Vector256<float> scale = Vector256.Create(1 / this.MaximumValue);
3232
nuint n = values.Component0.Vector256Count<float>();
3333
for (nuint i = 0; i < n; i++)
3434
{

src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected override void ConvertToRgbInplaceVectorized(in ComponentValues values)
2626
ref Vector<float> bBase =
2727
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component2));
2828

29-
var scale = new Vector<float>(1 / this.MaximumValue);
29+
Vector<float> scale = new Vector<float>(1 / this.MaximumValue);
3030

3131
nuint n = values.Component0.VectorCount<float>();
3232
for (nuint i = 0; i < n; i++)

0 commit comments

Comments
 (0)