Browse Source

BufferPointer<T>.Clear()

af/merge-core
Anton Firszov 9 years ago
parent
commit
bf92d664e4
  1. 10
      src/ImageSharp/Common/Memory/BufferPointer{T}.cs
  2. 43
      tests/ImageSharp.Benchmarks/General/ClearBuffer.cs
  3. 20
      tests/ImageSharp.Tests/Common/BufferPointerTests.cs

10
src/ImageSharp/Common/Memory/BufferPointer{T}.cs

@ -122,5 +122,15 @@ namespace ImageSharp
result.PointerAtOffset = this.PointerAtOffset + (Unsafe.SizeOf<T>() * offset);
return result;
}
/// <summary>
/// Clears `count` elements beginning from the pointed position.
/// </summary>
/// <param name="count">The number of elements to clear</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Clear(int count)
{
}
}
}

43
tests/ImageSharp.Benchmarks/General/ClearBuffer.cs

@ -0,0 +1,43 @@
// ReSharper disable InconsistentNaming
namespace ImageSharp.Benchmarks.General
{
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BenchmarkDotNet.Attributes;
using Color = ImageSharp.Color;
public unsafe class ClearBuffer
{
private PinnedBuffer<Color> buffer;
[Params(32, 128, 512)]
public int Count { get; set; }
[Setup]
public void Setup()
{
this.buffer = new PinnedBuffer<ImageSharp.Color>(this.Count);
}
[Cleanup]
public void Cleanup()
{
this.buffer.Dispose();
}
[Benchmark(Baseline = true)]
public void Array_Clear()
{
Array.Clear(this.buffer.Array, 0, this.Count);
}
[Benchmark]
public void Unsafe_InitBlock()
{
Unsafe.InitBlock((void*)this.buffer.Pointer, default(byte), (uint)this.Count*sizeof(uint));
}
}
}

20
tests/ImageSharp.Tests/Common/BufferPointerTests.cs

@ -131,6 +131,25 @@ namespace ImageSharp.Tests.Common
}
}
[Theory]
[InlineData(4)]
[InlineData(1500)]
public void Clear(int count)
{
Foo[] array = Foo.CreateArray(count + 42);
int offset = 2;
fixed (Foo* p = array)
{
BufferPointer<Foo> ap = new BufferPointer<Foo>(array, p, offset);
// Act:
ap.Clear(count);
}
}
public class Copy
{
private static void AssertNotDefault<T>(T[] data, int idx)
@ -319,7 +338,6 @@ namespace ImageSharp.Tests.Common
Assert.False(ElementsAreEqual(source, dest, count));
}
[Theory]
[InlineData(4)]
[InlineData(1500)]

Loading…
Cancel
Save