Browse Source

Avoid slicing spans by constructing directly from array

af/merge-core
Jason Nelson 8 years ago
parent
commit
eb732f9deb
  1. 4
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  2. 2
      src/ImageSharp/Memory/BasicArrayBuffer.cs

4
src/ImageSharp/Formats/Png/PngEncoderCore.cs

@ -525,8 +525,8 @@ namespace SixLabors.ImageSharp.Formats.Png
int dpmX = (int)Math.Round(image.MetaData.HorizontalResolution * 39.3700787D);
int dpmY = (int)Math.Round(image.MetaData.VerticalResolution * 39.3700787D);
BinaryPrimitives.WriteInt32BigEndian(this.chunkDataBuffer.AsSpan().Slice(0, 4), dpmX);
BinaryPrimitives.WriteInt32BigEndian(this.chunkDataBuffer.AsSpan().Slice(4, 4), dpmY);
BinaryPrimitives.WriteInt32BigEndian(new Span<byte>(this.chunkDataBuffer, 0, 4), dpmX);
BinaryPrimitives.WriteInt32BigEndian(new Span<byte>(this.chunkDataBuffer, 4, 4), dpmY);
this.chunkDataBuffer[8] = 1;

2
src/ImageSharp/Memory/BasicArrayBuffer.cs

@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.Memory
public int Length { get; }
public Span<T> Span => this.Array.AsSpan().Slice(0, this.Length);
public Span<T> Span => new Span<T>(this.Array, 0, this.Length);
/// <summary>
/// Returns a reference to specified element of the buffer.

Loading…
Cancel
Save