Skip to content

Commit 461e59d

Browse files
Optimize and fix warnings.
1 parent 14226ce commit 461e59d

File tree

5 files changed

+17
-20
lines changed

5 files changed

+17
-20
lines changed

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,7 @@ public static Block8x8F Load(Span<int> data)
153153
/// </summary>
154154
[MethodImpl(InliningOptions.ShortMethod)]
155155
public void Clear()
156-
{
157-
// The cheapest way to do this in C#:
158-
this = default;
159-
}
156+
=> this = default; // The cheapest way to do this in C#:
160157

161158
/// <summary>
162159
/// Load raw 32bit floating point data from source.
@@ -178,9 +175,7 @@ public void LoadFrom(Span<float> source)
178175
/// <param name="source">Source</param>
179176
[MethodImpl(InliningOptions.ShortMethod)]
180177
public static unsafe void LoadFrom(Block8x8F* blockPtr, Span<float> source)
181-
{
182-
blockPtr->LoadFrom(source);
183-
}
178+
=> blockPtr->LoadFrom(source);
184179

185180
/// <summary>
186181
/// Load raw 32bit floating point data from source
@@ -234,9 +229,7 @@ public static unsafe void ScaledCopyTo(Block8x8F* blockPtr, Span<byte> dest)
234229
/// <param name="dest">The destination.</param>
235230
[MethodImpl(InliningOptions.ShortMethod)]
236231
public static unsafe void ScaledCopyTo(Block8x8F* blockPtr, Span<float> dest)
237-
{
238-
blockPtr->ScaledCopyTo(dest);
239-
}
232+
=> blockPtr->ScaledCopyTo(dest);
240233

241234
/// <summary>
242235
/// Copy raw 32bit floating point data to dest
@@ -437,7 +430,6 @@ public void AddInPlace(float value)
437430
/// <param name="blockPtr">The block pointer.</param>
438431
/// <param name="qtPtr">The qt pointer.</param>
439432
/// <param name="unzigPtr">Unzig pointer</param>
440-
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
441433
public static unsafe void DequantizeBlock(Block8x8F* blockPtr, Block8x8F* qtPtr, byte* unzigPtr)
442434
{
443435
float* b = (float*)blockPtr;
@@ -565,14 +557,15 @@ private static void DivideRoundAll(ref Block8x8F a, ref Block8x8F b)
565557
ref Vector256<float> bBase = ref Unsafe.AsRef(Unsafe.As<Vector4, Vector256<float>>(ref b.V0L));
566558
ref Vector256<float> aEnd = ref Unsafe.Add(ref aBase, 8);
567559

568-
while (Unsafe.IsAddressLessThan(ref aBase, ref aEnd))
560+
do
569561
{
570562
Vector256<float> voff = Avx.Multiply(Avx.Min(Avx.Max(vnegOne, aBase), vone), vadd);
571563
Unsafe.Add(ref aBase, 0) = Avx.Add(Avx.Divide(aBase, bBase), voff);
572564

573565
aBase = ref Unsafe.Add(ref aBase, 1);
574566
bBase = ref Unsafe.Add(ref bBase, 1);
575567
}
568+
while (Unsafe.IsAddressLessThan(ref aBase, ref aEnd));
576569
}
577570
else
578571
#endif

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,15 @@ private set
7878
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7979
public void Update(Buffer2D<T> buffer, int startY)
8080
{
81-
int y = startY;
82-
int height = buffer.Height;
83-
8481
// We don't actually have to assign values outside of the
8582
// frame pixel buffer since they are never requested.
86-
for (int i = 0; i < 8 && y < height; i++)
83+
int y = startY;
84+
int yEnd = Math.Min(y + 8, buffer.Height);
85+
86+
int i = 0;
87+
while (y < yEnd)
8788
{
88-
this[i] = buffer.GetRowSpan(y++);
89+
this[i++] = buffer.GetRowSpan(y++);
8990
}
9091
}
9192

tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_Scale16X16To8X8.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Apache License, Version 2.0.
3+
14
using System;
25
using BenchmarkDotNet.Attributes;
36
using SixLabors.ImageSharp.Formats.Jpeg.Components;
@@ -15,7 +18,7 @@ public void Setup()
1518
{
1619
var random = new Random();
1720

18-
float[] f = new float[8*8];
21+
float[] f = new float[8 * 8];
1922
for (int i = 0; i < f.Length; i++)
2023
{
2124
f[i] = (float)random.NextDouble();

tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ public void WrapMemory_MemoryOfT_ValidSize(int size, int height, int width)
375375
var array = new Rgba32[size];
376376
var memory = new Memory<Rgba32>(array);
377377

378-
Image.WrapMemory(memory, height, width);
378+
Image.WrapMemory(memory, height, width);
379379
}
380380

381381
private class TestMemoryOwner<T> : IMemoryOwner<T>

tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ static FileInfo Find(DirectoryInfo root, string name)
263263
private static string GetNetCoreVersion()
264264
{
265265
Assembly assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
266-
string[] assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
266+
string[] assemblyPath = assembly.Location.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
267267
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
268268
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
269269
{

0 commit comments

Comments
 (0)