diff --git a/src/Aardvark.Base.IO/Aardvark.Base.IO.csproj b/src/Aardvark.Base.IO/Aardvark.Base.IO.csproj index 6f540866..a77a9a50 100644 --- a/src/Aardvark.Base.IO/Aardvark.Base.IO.csproj +++ b/src/Aardvark.Base.IO/Aardvark.Base.IO.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + net6.0;netstandard2.0 true 612;1591 true diff --git a/src/Aardvark.Base.IO/StreamCodeReader.cs b/src/Aardvark.Base.IO/StreamCodeReader.cs index adc11982..7a37a6de 100644 --- a/src/Aardvark.Base.IO/StreamCodeReader.cs +++ b/src/Aardvark.Base.IO/StreamCodeReader.cs @@ -123,6 +123,25 @@ public long ReadArray(T[] array, long index, long count) where T : struct { if (count < 1) return 0; + +#if NET6_0_OR_GREATER + var span = MemoryMarshal.AsBytes(array.AsSpan((int)index, (int)count)); + + var sizeOfT = span.Length / array.Length; + var bytesToRead = span.Length; + var offset = 0; + + do + { + int finished = base.Read(span); + if (finished == 0) break; + offset += finished; bytesToRead -= finished; + span = span.Slice(offset, bytesToRead); + } + while (bytesToRead > 0); + + return offset / sizeOfT; +#else unsafe { var sizeOfT = Marshal.SizeOf(typeof(T)); @@ -152,6 +171,7 @@ public long ReadArray(T[] array, long index, long count) } return ((long)(offset / sizeOfT) - index); } +#endif } public long ReadArray(T[,] array, long count)