Browse Source

Ben Adams is a wizard

pull/549/head
James Jackson-South 8 years ago
parent
commit
75050c52fe
  1. 25
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs

25
src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs

@ -3,6 +3,7 @@
using System; using System;
using System.IO; using System.IO;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
// TODO: This could be useful elsewhere. // TODO: This could be useful elsewhere.
@ -70,6 +71,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
/// byte, or returns -1 if at the end of the stream. /// byte, or returns -1 if at the end of the stream.
/// </summary> /// </summary>
/// <returns>The unsigned byte cast to an <see cref="int"/>, or -1 if at the end of the stream.</returns> /// <returns>The unsigned byte cast to an <see cref="int"/>, or -1 if at the end of the stream.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int ReadByte() public int ReadByte()
{ {
if (this.position >= this.Length) if (this.position >= this.Length)
@ -79,13 +81,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
if (this.position == 0 || this.bytesRead >= ChunkLength) if (this.position == 0 || this.bytesRead >= ChunkLength)
{ {
this.stream.Seek(this.position, SeekOrigin.Begin); return this.ReadByteSlow();
this.stream.Read(this.chunk, 0, ChunkLength); }
this.bytesRead = 0; else
{
this.position++;
return this.chunk[this.bytesRead++];
} }
this.position++;
return this.chunk[this.bytesRead++];
} }
/// <summary> /// <summary>
@ -152,5 +154,16 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
{ {
this.buffer?.Dispose(); this.buffer?.Dispose();
} }
[MethodImpl(MethodImplOptions.NoInlining)]
private int ReadByteSlow()
{
this.stream.Seek(this.position, SeekOrigin.Begin);
this.stream.Read(this.chunk, 0, ChunkLength);
this.bytesRead = 0;
this.position++;
return this.chunk[this.bytesRead++];
}
} }
} }
Loading…
Cancel
Save