Browse Source

Remove final allocations

pull/1108/head
James Jackson-South 6 years ago
parent
commit
e3a7bb40c5
  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
{
private readonly WrappingRowIntervalInfo info;
@ -63,13 +63,9 @@ namespace SixLabors.ImageSharp.Advanced.ParallelUtils
}
int yMax = Math.Min(yMin + this.info.StepY, this.info.MaxY);
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);
}
internal readonly struct WrappingRowIntervalAction<T, TBuffer> : IRowIntervalAction<TBuffer>
internal readonly struct WrappingRowIntervalAction<T, TBuffer>
where T : struct, IRowIntervalAction<TBuffer>
where TBuffer : unmanaged
{
@ -52,16 +52,12 @@ namespace SixLabors.ImageSharp.Advanced.ParallelUtils
}
int yMax = Math.Min(yMin + this.info.StepY, this.info.MaxY);
var rows = new RowInterval(yMin, yMax);
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,
numOfSteps,
parallelOptions,
i => rowAction.Invoke(i));
rowAction.Invoke);
}
/// <summary>
@ -136,8 +136,7 @@ namespace SixLabors.ImageSharp.Advanced.ParallelUtils
0,
numOfSteps,
parallelOptions,
i =>
rowAction.Invoke(i));
rowAction.Invoke);
}
/// <summary>

Loading…
Cancel
Save