diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs
index eb562424d..458ddc462 100644
--- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs
+++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/DoubleBufferedStreamReader.cs
@@ -3,6 +3,7 @@
using System;
using System.IO;
+using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Memory;
// 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.
///
/// The unsigned byte cast to an , or -1 if at the end of the stream.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public int ReadByte()
{
if (this.position >= this.Length)
@@ -79,13 +81,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
if (this.position == 0 || this.bytesRead >= ChunkLength)
{
- this.stream.Seek(this.position, SeekOrigin.Begin);
- this.stream.Read(this.chunk, 0, ChunkLength);
- this.bytesRead = 0;
+ return this.ReadByteSlow();
+ }
+ else
+ {
+ this.position++;
+ return this.chunk[this.bytesRead++];
}
-
- this.position++;
- return this.chunk[this.bytesRead++];
}
///
@@ -152,5 +154,16 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
{
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++];
+ }
}
}
\ No newline at end of file