Browse Source

Remove final allocations

af/octree-no-pixelmap
James Jackson-South 6 years ago
parent
commit
c41656688c
  1. 8
      src/ImageSharp/Advanced/ParallelUtils/IRowIntervalAction.cs
  2. 8
      src/ImageSharp/Advanced/ParallelUtils/IRowIntervalAction{TBuffer}.cs
  3. 5
      src/ImageSharp/Advanced/ParallelUtils/ParallelHelper.cs

8
src/ImageSharp/Advanced/ParallelUtils/IRowIntervalAction.cs

@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.Advanced.ParallelUtils
} }
} }
internal readonly struct WrappingRowIntervalAction<T> : IRowIntervalAction internal readonly struct WrappingRowIntervalAction<T>
where T : struct, IRowIntervalAction where T : struct, IRowIntervalAction
{ {
private readonly WrappingRowIntervalInfo info; private readonly WrappingRowIntervalInfo info;
@ -63,13 +63,9 @@ namespace SixLabors.ImageSharp.Advanced.ParallelUtils
} }
int yMax = Math.Min(yMin + this.info.StepY, this.info.MaxY); int yMax = Math.Min(yMin + this.info.StepY, this.info.MaxY);
var rows = new RowInterval(yMin, yMax); var rows = new RowInterval(yMin, yMax);
this.Invoke(in rows); this.action.Invoke(in rows);
} }
[MethodImpl(InliningOptions.ShortMethod)]
public void Invoke(in RowInterval rows) => this.action.Invoke(in rows);
} }
} }

8
src/ImageSharp/Advanced/ParallelUtils/IRowIntervalAction{TBuffer}.cs

@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp.Advanced.ParallelUtils
void Invoke(in RowInterval rows, Memory<TBuffer> memory); void Invoke(in RowInterval rows, Memory<TBuffer> memory);
} }
internal readonly struct WrappingRowIntervalAction<T, TBuffer> : IRowIntervalAction<TBuffer> internal readonly struct WrappingRowIntervalAction<T, TBuffer>
where T : struct, IRowIntervalAction<TBuffer> where T : struct, IRowIntervalAction<TBuffer>
where TBuffer : unmanaged where TBuffer : unmanaged
{ {
@ -52,16 +52,12 @@ namespace SixLabors.ImageSharp.Advanced.ParallelUtils
} }
int yMax = Math.Min(yMin + this.info.StepY, this.info.MaxY); int yMax = Math.Min(yMin + this.info.StepY, this.info.MaxY);
var rows = new RowInterval(yMin, yMax); var rows = new RowInterval(yMin, yMax);
using (IMemoryOwner<TBuffer> buffer = this.allocator.Allocate<TBuffer>(this.info.MaxX)) using (IMemoryOwner<TBuffer> buffer = this.allocator.Allocate<TBuffer>(this.info.MaxX))
{ {
this.Invoke(in rows, buffer.Memory); this.action.Invoke(in rows, buffer.Memory);
} }
} }
[MethodImpl(InliningOptions.ShortMethod)]
public void Invoke(in RowInterval rows, Memory<TBuffer> memory) => this.action.Invoke(in rows, memory);
} }
} }

5
src/ImageSharp/Advanced/ParallelUtils/ParallelHelper.cs

@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Advanced.ParallelUtils
0, 0,
numOfSteps, numOfSteps,
parallelOptions, parallelOptions,
i => rowAction.Invoke(i)); rowAction.Invoke);
} }
/// <summary> /// <summary>
@ -136,8 +136,7 @@ namespace SixLabors.ImageSharp.Advanced.ParallelUtils
0, 0,
numOfSteps, numOfSteps,
parallelOptions, parallelOptions,
i => rowAction.Invoke);
rowAction.Invoke(i));
} }
/// <summary> /// <summary>

Loading…
Cancel
Save