Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c327b28
Improve perf of XmlBinaryWriter using Unsafe
Daniel-Svensson Jun 28, 2022
d57b7f2
Use ReverseEndianness to simplify writes
Daniel-Svensson Jun 28, 2022
c214302
Use span in a few places
Daniel-Svensson Jun 28, 2022
0e736f6
Add back old comparison, but only write float as int if it saves space
Daniel-Svensson Jun 29, 2022
d1e850b
Use span in array writing to reduce bounds checks
Daniel-Svensson Jun 29, 2022
d80b67f
Extract all unsafe code to shared method
Daniel-Svensson Jun 30, 2022
d24de76
Fix nodetype type
Daniel-Svensson Jun 30, 2022
c98689b
Avoid pinning and unsafe when writing arrays
Daniel-Svensson Jul 1, 2022
cf64f69
Merge remote-tracking branch 'upstream/main' into dev
Daniel-Svensson Jul 3, 2022
450e4d8
add back CheckArray
Daniel-Svensson Jul 3, 2022
149b6d9
Fix Assert condition
Daniel-Svensson Jul 4, 2022
2907e0a
Apply suggestions from code review
Daniel-Svensson Jul 8, 2022
86496bb
Fix review comments
Daniel-Svensson Jul 8, 2022
ed26c86
Merge remote-tracking branch 'upstream/main' into dev
Daniel-Svensson Jul 8, 2022
657e9b9
use new span ctor
Daniel-Svensson Jul 8, 2022
0a7a7e5
add tests
Daniel-Svensson Jul 25, 2022
963315d
Add tests for very long arrays
Daniel-Svensson Jul 25, 2022
c2e11d0
Fixx overload resolution for WriteText method
Daniel-Svensson Jul 26, 2022
e832548
Just copy guid arrays on LittleEndian platforms
Daniel-Svensson Aug 3, 2022
1d1818e
Merge remote-tracking branch 'upstream/main' into dev
Daniel-Svensson Aug 14, 2022
571a628
Add testversion of XmlBinaryNodeType with hardcoded values to use sam…
Daniel-Svensson Aug 14, 2022
5488341
call corrreect version of getbuffer
Daniel-Svensson Aug 15, 2022
c983179
Merge branch 'main' into dev
Daniel-Svensson Aug 16, 2022
ce69dce
Update src/libraries/System.Runtime.Serialization.Xml/tests/Reflectio…
Daniel-Svensson Aug 16, 2022
9281073
fix merge conflict
Daniel-Svensson Aug 16, 2022
798286a
Fix merge conflicts.
StephenMolloy Mar 16, 2023
ab3e0cc
Restored Big-Endian functionality. Ugly though.
StephenMolloy Mar 16, 2023
477cf8b
Cleaned up arrays.
StephenMolloy Mar 17, 2023
f51e07d
Merge branch 'main' into dev
StephenMolloy Mar 25, 2023
1fb4ba0
Remove leftover using in tests.
StephenMolloy Mar 31, 2023
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
Prev Previous commit
Next Next commit
Add tests for very long arrays
  • Loading branch information
Daniel-Svensson committed Jul 25, 2022
commit 963315d047e63d0f409c5ad70e260f530b6cc645
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ public static void BinaryWriter_PrimitiveTypes()
double d = 1.0 / 3.0;
Guid guid = Guid.NewGuid();

// Remarks: Of these types only timespan handles BigEndian/LittleEndian so for other types compare against bare bytes
AssertBytesWritten(x => x.WriteValue(decimal.MaxValue), XmlBinaryNodeType.DecimalText, MemoryMarshal.AsBytes(new ReadOnlySpan<decimal>(in decMax)));
AssertBytesWritten(x => x.WriteValue(f), XmlBinaryNodeType.FloatText, MemoryMarshal.AsBytes(new ReadOnlySpan<float>(in f)));
AssertBytesWritten(x => x.WriteValue(guid), XmlBinaryNodeType.GuidText, guid.ToByteArray());
Expand Down Expand Up @@ -381,7 +382,7 @@ void AssertBytesWritten(Action<XmlDictionaryWriter> action, XmlBinaryNodeType no


[Fact]
public static void BinaryWriter_Array()
public static void BinaryWriter_Arrays()
{
using var ms = new MemoryStream();
using var writer = XmlDictionaryWriter.CreateBinaryWriter(ms);
Expand All @@ -393,6 +394,10 @@ public static void BinaryWriter_Array()

AssertBytesWritten(x => x.WriteArray(null, "a", null, ints, offset, count), XmlBinaryNodeType.Int32TextWithEndElement, count, new byte[] { 4, 3, 2, 1, 0x44, 0x33, 0x22, 0x11 });

// Write more than 512 bytes in a single call to trigger different writing logic in XmlStreamNodeWriter.WriteBytes
long[] longs = Enumerable.Range(0x01020304, 127).Select(i => (long)i | (long)(~i << 32)).ToArray();
AssertBytesWritten(x => x.WriteArray(null, "a", null, longs, 0, longs.Length), XmlBinaryNodeType.Int64TextWithEndElement, longs.Length, MemoryMarshal.AsBytes(longs.AsSpan()));

void AssertBytesWritten(Action<XmlDictionaryWriter> action, XmlBinaryNodeType nodeType, int count, ReadOnlySpan<byte> expected)
{
// Reset stream so we only compare the actual value written (including end element)
Expand All @@ -407,11 +412,9 @@ void AssertBytesWritten(Action<XmlDictionaryWriter> action, XmlBinaryNodeType no

var actual = segement.AsSpan();
Assert.Equal(XmlBinaryNodeType.Array, (XmlBinaryNodeType)actual[0]);

//// start element: ShortDictionaryElement + lenght of str + str
Assert.Equal(XmlBinaryNodeType.ShortElement, (XmlBinaryNodeType)actual[1]);
int elementLenght = actual[2];
Assert.InRange(actual[2], 0, 0x8f);
Assert.InRange(elementLenght, 0, 0x8f); // verify count is single byte
Assert.Equal(XmlBinaryNodeType.EndElement, (XmlBinaryNodeType)actual[3 + elementLenght]);

actual = actual.Slice(4 + elementLenght);
Expand All @@ -420,7 +423,6 @@ void AssertBytesWritten(Action<XmlDictionaryWriter> action, XmlBinaryNodeType no
Assert.Equal(checked((sbyte)count), (sbyte)actual[1]);

AssertExtensions.SequenceEqual(expected, actual.Slice(2));
writer.WriteEndElement();
}
}

Expand Down