Skip to content

Commit 1837bff

Browse files
authored
Merge pull request #405 from drewnoakes/reduce-reader-get-byte-overhead
Reduce overhead reading byte/sbyte arrays from IndexedReader
2 parents f48737f + f2c7446 commit 1837bff

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

MetadataExtractor/Formats/Tiff/TiffReader.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Copyright (c) Drew Noakes and contributors. All Rights Reserved. Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
22

3+
using System.Runtime.InteropServices;
4+
35
namespace MetadataExtractor.Formats.Tiff
46
{
57
/// <summary>
@@ -384,8 +386,8 @@ private static void ProcessTag(ITiffHandler handler, int tagId, int tagValueOffs
384386
else
385387
{
386388
var array = new sbyte[componentCount];
387-
for (var i = 0; i < componentCount; i++)
388-
array[i] = reader.GetSByte(tagValueOffset + i);
389+
var bytes = MemoryMarshal.Cast<sbyte, byte>(array);
390+
reader.GetBytes(tagValueOffset, bytes);
389391
handler.SetInt8SArray(tagId, array);
390392
}
391393
break;
@@ -399,8 +401,7 @@ private static void ProcessTag(ITiffHandler handler, int tagId, int tagValueOffs
399401
else
400402
{
401403
var array = new byte[componentCount];
402-
for (var i = 0; i < componentCount; i++)
403-
array[i] = reader.GetByte(tagValueOffset + i);
404+
reader.GetBytes(tagValueOffset, array);
404405
handler.SetInt8UArray(tagId, array);
405406
}
406407
break;

0 commit comments

Comments
 (0)