Skip to content

Commit

Permalink
Merge pull request #410 from drewnoakes/use-spans-in-dotnet-8
Browse files Browse the repository at this point in the history
Use spans in readers in .NET 8
  • Loading branch information
drewnoakes authored Feb 18, 2024
2 parents 4505428 + 990e635 commit 3fdeeb0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions MetadataExtractor/IO/IndexedSeekingReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public IndexedSeekingReader(Stream stream, int baseOffset = 0, bool isMotorolaBy

public override long Length { get; }

#if !NETSTANDARD2_1
#if !NETSTANDARD2_1 && !NET8_0_OR_GREATER
private readonly byte[] _buffer = new byte[2048];
#endif

Expand All @@ -59,7 +59,7 @@ public override void GetBytes(int index, Span<byte> bytes)
while (totalBytesRead != bytes.Length)
{
var target = bytes.Slice(totalBytesRead);
#if NETSTANDARD2_1
#if NETSTANDARD2_1 || NET8_0_OR_GREATER
var bytesRead = _stream.Read(target);
#else
var len = Math.Min(bytes.Length - totalBytesRead, _buffer.Length);
Expand All @@ -75,7 +75,6 @@ public override void GetBytes(int index, Span<byte> bytes)

Debug.Assert(totalBytesRead <= bytes.Length);
}

}

private void Seek(int index)
Expand Down
4 changes: 2 additions & 2 deletions MetadataExtractor/IO/SequentialStreamReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override void GetBytes(byte[] buffer, int offset, int count)
}
}

#if !NETSTANDARD2_1
#if !NETSTANDARD2_1 && !NET8_0_OR_GREATER
private readonly byte[] _buffer = new byte[2048];
#endif

Expand All @@ -62,7 +62,7 @@ public override void GetBytes(Span<byte> bytes)
while (totalBytesRead != bytes.Length)
{
var target = bytes.Slice(totalBytesRead);
#if NETSTANDARD2_1
#if NETSTANDARD2_1 || NET8_0_OR_GREATER
var bytesRead = _stream.Read(target);
#else
var len = Math.Min(bytes.Length - totalBytesRead, _buffer.Length);
Expand Down

0 comments on commit 3fdeeb0

Please sign in to comment.