Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;

namespace System.Xml
Expand Down Expand Up @@ -1250,10 +1251,7 @@ private unsafe int ReadArray(bool[] array, int offset, int count)
{
CheckArray(array, offset, count);
int actual = Math.Min(count, _arrayCount);
fixed (bool* items = &array[offset])
{
BufferReader.UnsafeReadArray((byte*)items, (byte*)&items[actual]);
}
BufferReader.ReadRawArrayBytes(array.AsSpan(offset, actual));
SkipArrayElements(actual);
return actual;
}
Expand All @@ -1276,10 +1274,7 @@ private unsafe int ReadArray(short[] array, int offset, int count)
{
CheckArray(array, offset, count);
int actual = Math.Min(count, _arrayCount);
fixed (short* items = &array[offset])
{
BufferReader.UnsafeReadArray((byte*)items, (byte*)&items[actual]);
}
BufferReader.ReadRawArrayBytes(array.AsSpan(offset, actual));
SkipArrayElements(actual);
return actual;
}
Expand All @@ -1302,10 +1297,7 @@ private unsafe int ReadArray(int[] array, int offset, int count)
{
CheckArray(array, offset, count);
int actual = Math.Min(count, _arrayCount);
fixed (int* items = &array[offset])
{
BufferReader.UnsafeReadArray((byte*)items, (byte*)&items[actual]);
}
BufferReader.ReadRawArrayBytes(array.AsSpan(offset, actual));
SkipArrayElements(actual);
return actual;
}
Expand All @@ -1328,10 +1320,7 @@ private unsafe int ReadArray(long[] array, int offset, int count)
{
CheckArray(array, offset, count);
int actual = Math.Min(count, _arrayCount);
fixed (long* items = &array[offset])
{
BufferReader.UnsafeReadArray((byte*)items, (byte*)&items[actual]);
}
BufferReader.ReadRawArrayBytes(array.AsSpan(offset, actual));
SkipArrayElements(actual);
return actual;
}
Expand All @@ -1354,10 +1343,7 @@ private unsafe int ReadArray(float[] array, int offset, int count)
{
CheckArray(array, offset, count);
int actual = Math.Min(count, _arrayCount);
fixed (float* items = &array[offset])
{
BufferReader.UnsafeReadArray((byte*)items, (byte*)&items[actual]);
}
BufferReader.ReadRawArrayBytes(array.AsSpan(offset, actual));
SkipArrayElements(actual);
return actual;
}
Expand All @@ -1380,10 +1366,7 @@ private unsafe int ReadArray(double[] array, int offset, int count)
{
CheckArray(array, offset, count);
int actual = Math.Min(count, _arrayCount);
fixed (double* items = &array[offset])
{
BufferReader.UnsafeReadArray((byte*)items, (byte*)&items[actual]);
}
BufferReader.ReadRawArrayBytes(array.AsSpan(offset, actual));
SkipArrayElements(actual);
return actual;
}
Expand All @@ -1406,10 +1389,7 @@ private unsafe int ReadArray(decimal[] array, int offset, int count)
{
CheckArray(array, offset, count);
int actual = Math.Min(count, _arrayCount);
fixed (decimal* items = &array[offset])
{
BufferReader.UnsafeReadArray((byte*)items, (byte*)&items[actual]);
}
BufferReader.ReadRawArrayBytes(array.AsSpan(offset, actual));
SkipArrayElements(actual);
return actual;
}
Expand All @@ -1433,9 +1413,11 @@ private int ReadArray(DateTime[] array, int offset, int count)
{
CheckArray(array, offset, count);
int actual = Math.Min(count, _arrayCount);
for (int i = 0; i < actual; i++)
// Try to read in whole array, but don't fail if not possible
BufferReader.GetBuffer(actual * ValueHandleLength.DateTime, out _, out _);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Se comment on UnsafeReadarray/ReadRawArrayBytes about chunked reads, if it should be added back then these GetBuffer calls should probably be removed
  2. Is it better to use overload with a single out parameter that throws an exception directly if the file ends prematurely ? The current approach keeps the old behaviour where these "special" types will partially fill arrays in case of premature end-of-file

foreach (ref DateTime item in array.AsSpan(offset, actual))
{
array[offset + i] = BufferReader.ReadDateTime();
item = BufferReader.ReadDateTime();
}
SkipArrayElements(actual);
return actual;
Expand All @@ -1460,9 +1442,18 @@ private int ReadArray(Guid[] array, int offset, int count)
{
CheckArray(array, offset, count);
int actual = Math.Min(count, _arrayCount);
for (int i = 0; i < actual; i++)
if (BitConverter.IsLittleEndian)
{
array[offset + i] = BufferReader.ReadGuid();
BufferReader.ReadRawArrayBytes(array.AsSpan(offset, actual));
}
else
{
// Try to read in whole array, but don't fail if not possible
BufferReader.GetBuffer(actual * ValueHandleLength.Guid, out _, out _);
foreach (ref Guid item in array.AsSpan(offset, actual))
{
item = BufferReader.ReadGuid();
}
}
SkipArrayElements(actual);
return actual;
Expand All @@ -1487,9 +1478,11 @@ private int ReadArray(TimeSpan[] array, int offset, int count)
{
CheckArray(array, offset, count);
int actual = Math.Min(count, _arrayCount);
for (int i = 0; i < actual; i++)
// Try to read in whole array, but don't fail if not possible
BufferReader.GetBuffer(actual * ValueHandleLength.TimeSpan, out _, out _);
foreach (ref TimeSpan item in array.AsSpan(offset, actual))
{
array[offset + i] = BufferReader.ReadTimeSpan();
item = BufferReader.ReadTimeSpan();
}
SkipArrayElements(actual);
return actual;
Expand Down
Loading