Skip to content

Instantly share code, notes, and snippets.

@benaadams
Last active April 28, 2018 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benaadams/ab108da55eba2b9a3d97c8a0dce97bc2 to your computer and use it in GitHub Desktop.
Save benaadams/ab108da55eba2b9a3d97c8a0dce97bc2 to your computer and use it in GitHub Desktop.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int ReadByte()
{
if (this.position >= this.Length)
{
return -1;
}
if (this.position == 0 || this.bytesRead >= ChunkLength)
{
return ReadByteSlow();
}
else
{
this.position++;
return this.chunk[this.bytesRead++];
}
}
[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++];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment