Skip to content

Commit

Permalink
Use explicit types instead of var
Browse files Browse the repository at this point in the history
  • Loading branch information
stefannikolei committed Dec 22, 2024
1 parent a6b4d82 commit 95b56d3
Show file tree
Hide file tree
Showing 271 changed files with 1,550 additions and 1,549 deletions.
2 changes: 1 addition & 1 deletion shared-infrastructure
4 changes: 2 additions & 2 deletions src/ImageSharp/Advanced/ParallelRowIterator.Wrappers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void Invoke(int i)
}

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

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

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

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

Expand Down
28 changes: 14 additions & 14 deletions src/ImageSharp/Advanced/ParallelRowIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static partial class ParallelRowIterator
public static void IterateRows<T>(Configuration configuration, Rectangle rectangle, in T operation)
where T : struct, IRowOperation
{
var parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
ParallelExecutionSettings parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
IterateRows(rectangle, in parallelSettings, in operation);
}

Expand Down Expand Up @@ -65,8 +65,8 @@ public static void IterateRows<T>(
}

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

Parallel.For(
0,
Expand All @@ -88,7 +88,7 @@ public static void IterateRows<T, TBuffer>(Configuration configuration, Rectangl
where T : struct, IRowOperation<TBuffer>
where TBuffer : unmanaged
{
var parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
ParallelExecutionSettings parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
IterateRows<T, TBuffer>(rectangle, in parallelSettings, in operation);
}

Expand Down Expand Up @@ -135,8 +135,8 @@ public static void IterateRows<T, TBuffer>(
}

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

Parallel.For(
0,
Expand All @@ -156,7 +156,7 @@ public static void IterateRows<T, TBuffer>(
public static void IterateRowIntervals<T>(Configuration configuration, Rectangle rectangle, in T operation)
where T : struct, IRowIntervalOperation
{
var parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
ParallelExecutionSettings parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
IterateRowIntervals(rectangle, in parallelSettings, in operation);
}

Expand Down Expand Up @@ -186,14 +186,14 @@ public static void IterateRowIntervals<T>(
// Avoid TPL overhead in this trivial case:
if (numOfSteps == 1)
{
var rows = new RowInterval(top, bottom);
RowInterval rows = new RowInterval(top, bottom);
Unsafe.AsRef(in operation).Invoke(in rows);
return;
}

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

Parallel.For(
0,
Expand All @@ -215,7 +215,7 @@ public static void IterateRowIntervals<T, TBuffer>(Configuration configuration,
where T : struct, IRowIntervalOperation<TBuffer>
where TBuffer : unmanaged
{
var parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
ParallelExecutionSettings parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration);
IterateRowIntervals<T, TBuffer>(rectangle, in parallelSettings, in operation);
}

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

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

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

Parallel.For(
0,
Expand Down
10 changes: 5 additions & 5 deletions src/ImageSharp/Common/Helpers/Numerics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,8 @@ private static void ClampImpl<T>(Span<T> span, T min, T max)
where T : unmanaged
{
ref T sRef = ref MemoryMarshal.GetReference(span);
var vmin = new Vector<T>(min);
var vmax = new Vector<T>(max);
Vector<T> vmin = new Vector<T>(min);
Vector<T> vmax = new Vector<T>(max);

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

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

var v128_13rd = Vector128.Create(1 / 3f);
var v128_23rds = Vector128.Create(2 / 3f);
Vector128<float> v128_13rd = Vector128.Create(1 / 3f);
Vector128<float> v128_23rds = Vector128.Create(2 / 3f);

while (Unsafe.IsAddressLessThan(ref vectors128Ref, ref vectors128End))
{
Expand Down
10 changes: 5 additions & 5 deletions src/ImageSharp/Common/Helpers/SimdUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ internal static Vector<float> FastRound(this Vector<float> v)
}
else
{
var magic0 = new Vector<int>(int.MinValue); // 0x80000000
var sgn0 = Vector.AsVectorSingle(magic0);
var and0 = Vector.BitwiseAnd(sgn0, v);
var or0 = Vector.BitwiseOr(and0, new Vector<float>(8388608.0f));
var add0 = Vector.Add(v, or0);
Vector<int> magic0 = new Vector<int>(int.MinValue); // 0x80000000
Vector<float> sgn0 = Vector.AsVectorSingle(magic0);
Vector<float> and0 = Vector.BitwiseAnd(sgn0, v);
Vector<float> or0 = Vector.BitwiseOr(and0, new Vector<float>(8388608.0f));
Vector<float> add0 = Vector.Add(v, or0);
return Vector.Subtract(add0, or0);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Jpeg/Components/Block8x8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void LoadFrom(Span<int> source)
/// <inheritdoc />
public override string ToString()
{
var sb = new StringBuilder();
StringBuilder? sb = new StringBuilder();
sb.Append('[');
for (int i = 0; i < Size; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ static void WidenCopyRowImpl2x2(ref Vector4 selfBase, ref Vector2 destBase, nuin
ref Vector4 dTopLeft = ref Unsafe.As<Vector2, Vector4>(ref Unsafe.Add(ref destBase, offset));
ref Vector4 dBottomLeft = ref Unsafe.As<Vector2, Vector4>(ref Unsafe.Add(ref destBase, offset + destStride));

var xyLeft = new Vector4(sLeft.X);
Vector4 xyLeft = new Vector4(sLeft.X);
xyLeft.Z = sLeft.Y;
xyLeft.W = sLeft.Y;

var zwLeft = new Vector4(sLeft.Z);
Vector4 zwLeft = new Vector4(sLeft.Z);
zwLeft.Z = sLeft.W;
zwLeft.W = sLeft.W;

var xyRight = new Vector4(sRight.X);
Vector4 xyRight = new Vector4(sRight.X);
xyRight.Z = sRight.Y;
xyRight.W = sRight.Y;

var zwRight = new Vector4(sRight.Z);
Vector4 zwRight = new Vector4(sRight.Z);
zwRight.Z = sRight.W;
zwRight.W = sRight.W;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override void ConvertToRgbInplace(in ComponentValues values)
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component3));

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

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

var scale = Vector128.Create(maxValue);
Vector128<float> scale = Vector128.Create(maxValue);

nint n = (nint)(uint)values.Component0.Length / Vector128<float>.Count;
for (nint i = 0; i < n; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override void ConvertToRgbInplace(in ComponentValues values)
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(values.Component3));

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

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

var scale = Vector256.Create(maxValue);
Vector256<float> scale = Vector256.Create(maxValue);

nuint n = values.Component0.Vector256Count<float>();
for (nuint i = 0; i < n; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected override void ConvertToRgbInplaceVectorized(in ComponentValues values)
ref Vector<float> kBase =
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component3));

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

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

// Used for the color conversion
var scale = new Vector<float>(maxValue);
Vector<float> scale = new Vector<float>(maxValue);

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

var kMask = Vector.Equals(ktmp, scale);
Vector<int> kMask = Vector.Equals(ktmp, scale);
ctmp = Vector.AndNot((ctmp - ktmp) / (scale - ktmp), kMask.As<int, float>());
mtmp = Vector.AndNot((mtmp - ktmp) / (scale - ktmp), kMask.As<int, float>());
ytmp = Vector.AndNot((ytmp - ktmp) / (scale - ktmp), kMask.As<int, float>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override void ConvertToRgbInplace(in ComponentValues values)
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component0));

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

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

// Used for the color conversion
var f0299 = Vector128.Create(0.299f);
var f0587 = Vector128.Create(0.587f);
var f0114 = Vector128.Create(0.114f);
Vector128<float> f0299 = Vector128.Create(0.299f);
Vector128<float> f0587 = Vector128.Create(0.587f);
Vector128<float> f0114 = Vector128.Create(0.114f);

nuint n = values.Component0.Vector128Count<float>();
for (nuint i = 0; i < n; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override void ConvertToRgbInplace(in ComponentValues values)
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(values.Component0));

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

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

// Used for the color conversion
var f0299 = Vector256.Create(0.299f);
var f0587 = Vector256.Create(0.587f);
var f0114 = Vector256.Create(0.114f);
Vector256<float> f0299 = Vector256.Create(0.299f);
Vector256<float> f0587 = Vector256.Create(0.587f);
Vector256<float> f0114 = Vector256.Create(0.114f);

nuint n = values.Component0.Vector256Count<float>();
for (nuint i = 0; i < n; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected override void ConvertToRgbInplaceVectorized(in ComponentValues values)
ref Vector<float> cBase =
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component0));

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

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

var rMult = new Vector<float>(0.299f);
var gMult = new Vector<float>(0.587f);
var bMult = new Vector<float>(0.114f);
Vector<float> rMult = new Vector<float>(0.299f);
Vector<float> gMult = new Vector<float>(0.587f);
Vector<float> bMult = new Vector<float>(0.114f);

nuint n = values.Component0.VectorCount<float>();
for (nuint i = 0; i < n; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override void ConvertToRgbInplace(in ComponentValues values)
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component2));

// Used for the color conversion
var scale = Vector128.Create(1 / this.MaximumValue);
Vector128<float> scale = Vector128.Create(1 / this.MaximumValue);
nuint n = values.Component0.Vector128Count<float>();
for (nuint i = 0; i < n; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override void ConvertToRgbInplace(in ComponentValues values)
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(values.Component2));

// Used for the color conversion
var scale = Vector256.Create(1 / this.MaximumValue);
Vector256<float> scale = Vector256.Create(1 / this.MaximumValue);
nuint n = values.Component0.Vector256Count<float>();
for (nuint i = 0; i < n; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected override void ConvertToRgbInplaceVectorized(in ComponentValues values)
ref Vector<float> bBase =
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component2));

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

nuint n = values.Component0.VectorCount<float>();
for (nuint i = 0; i < n; i++)
Expand Down
Loading

0 comments on commit 95b56d3

Please sign in to comment.