Browse Source

goodbye top-level Buffer<T>!

pull/475/head
Anton Firszov 8 years ago
parent
commit
f390569a01
  1. 2
      src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs
  2. 3
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsIDCT.cs
  3. 2
      src/ImageSharp/Memory/BasicArrayBuffer.cs
  4. 1
      src/ImageSharp/Memory/Buffer2DExtensions.cs
  5. 77
      src/ImageSharp/Memory/Buffer{T}.cs
  6. 14
      src/ImageSharp/Memory/IGetArray.cs

2
src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs

@ -5,8 +5,8 @@ using System;
using System.ComponentModel;
using System.Numerics;
using System.Runtime.CompilerServices;
// ReSharper disable CompareOfFloatsByEqualityOperator
// ReSharper disable CompareOfFloatsByEqualityOperator
namespace SixLabors.ImageSharp.ColorSpaces
{
/// <summary>

3
src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsIDCT.cs

@ -3,11 +3,10 @@
using System;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
{
using SixLabors.ImageSharp.Memory;
/// <summary>
/// Performs the inverse Descrete Cosine Transform on each frame component.
/// </summary>

2
src/ImageSharp/Memory/BasicArrayBuffer.cs

@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.Memory
return ref span[index];
}
}
public void Dispose()
{
}

1
src/ImageSharp/Memory/Buffer2DExtensions.cs

@ -12,7 +12,6 @@ namespace SixLabors.ImageSharp.Memory
/// </summary>
internal static class Buffer2DExtensions
{
/// <summary>
/// Gets a <see cref="Span{T}"/> to the row 'y' beginning from the pixel at 'x'.
/// </summary>

77
src/ImageSharp/Memory/Buffer{T}.cs

@ -1,77 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.Memory
{
/// <inheritdoc />
/// <summary>
/// Manages a buffer of value type objects as a Disposable resource.
/// The backing array is either pooled or comes from the outside.
/// </summary>
/// <typeparam name="T">The value type.</typeparam>
internal class Buffer<T> : IBuffer<T>, IGetArray<T>
where T : struct
{
private MemoryManager memoryManager;
// why is there such a rule? :S Protected should be fine for a field!
#pragma warning disable SA1401 // Fields should be private
/// <summary>
/// The backing array.
/// </summary>
protected T[] array;
#pragma warning restore SA1401 // Fields should be private
internal Buffer(T[] array, int length, MemoryManager memoryManager)
{
if (array.Length < length)
{
throw new ArgumentException("Can't initialize a PinnedBuffer with array.Length < count", nameof(array));
}
this.Length = length;
this.array = array;
this.memoryManager = memoryManager;
}
/// <summary>
/// Gets the count of "relevant" elements. It's usually smaller than 'Array.Length' when <see cref="array"/> is pooled.
/// </summary>
public int Length { get; private set; }
/// <summary>
/// Gets a <see cref="Span{T}"/> to the backing buffer.
/// </summary>
public Span<T> Span => new Span<T>(this.array, 0, this.Length);
/// <summary>
/// Disposes the <see cref="Buffer{T}"/> instance by unpinning the array, and returning the pooled buffer when necessary.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dispose()
{
if (this.array == null)
{
return;
}
this.memoryManager = null;
this.array = null;
this.Length = 0;
GC.SuppressFinalize(this);
}
/// <summary>
/// TODO: Refactor this
/// </summary>
T[] IGetArray<T>.GetArray()
{
return this.array;
}
}
}

14
src/ImageSharp/Memory/IGetArray.cs

@ -1,14 +0,0 @@
namespace SixLabors.ImageSharp.Memory
{
/// <summary>
/// Absolutely temporal.
/// </summary>
internal interface IGetArray<T>
where T : struct
{
/// <summary>
/// Absolutely temporal.
/// </summary>
T[] GetArray();
}
}
Loading…
Cancel
Save