diff options
5 files changed, 30 insertions, 38 deletions
diff --git a/src/System.Private.Xml/src/System/Xml/Core/XmlEncodedRawTextWriter.cs b/src/System.Private.Xml/src/System/Xml/Core/XmlEncodedRawTextWriter.cs index 4c7860d105..a1e6c3e1d2 100644 --- a/src/System.Private.Xml/src/System/Xml/Core/XmlEncodedRawTextWriter.cs +++ b/src/System.Private.Xml/src/System/Xml/Core/XmlEncodedRawTextWriter.cs @@ -180,10 +180,10 @@ namespace System.Xml if (!stream.CanSeek || stream.Position == 0) { - byte[] bom = encoding.GetPreamble(); + ReadOnlySpan<byte> bom = encoding.Preamble; if (bom.Length != 0) { - this.stream.Write(bom, 0, bom.Length); + this.stream.Write(bom); } } diff --git a/src/System.Private.Xml/src/System/Xml/Core/XmlRawTextWriterGenerator.cxx b/src/System.Private.Xml/src/System/Xml/Core/XmlRawTextWriterGenerator.cxx index 478b502c5c..b06d403251 100644 --- a/src/System.Private.Xml/src/System/Xml/Core/XmlRawTextWriterGenerator.cxx +++ b/src/System.Private.Xml/src/System/Xml/Core/XmlRawTextWriterGenerator.cxx @@ -210,9 +210,9 @@ namespace System.Xml { // Output UTF-8 byte order mark if Encoding object wants it if ( !stream.CanSeek || stream.Position == 0 ) { - byte[] bom = encoding.GetPreamble(); + ReadOnlySpan<byte> bom = encoding.Preamble; if ( bom.Length != 0 ) { - Buffer.BlockCopy( bom, 0, bufBytes, 1, bom.Length ); + bom.CopyTo(new Span<byte>(bufBytes, 1)); bufPos += bom.Length; textPos += bom.Length; } @@ -237,9 +237,9 @@ namespace System.Xml { encoder = encoding.GetEncoder(); if ( !stream.CanSeek || stream.Position == 0 ) { - byte[] bom = encoding.GetPreamble(); + ReadOnlySpan<byte> bom = encoding.Preamble; if ( bom.Length != 0 ) { - this.stream.Write( bom, 0, bom.Length ); + this.stream.Write( bom ); } } #endif diff --git a/src/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs b/src/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs index ea72797ef0..72bbed177d 100644 --- a/src/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs +++ b/src/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs @@ -2914,21 +2914,8 @@ namespace System.Xml } SetupEncoding(encoding); - // eat preamble - byte[] preamble = _ps.encoding.GetPreamble(); - int preambleLen = preamble.Length; - int i; - for (i = 0; i < preambleLen && i < _ps.bytesUsed; i++) - { - if (_ps.bytes[i] != preamble[i]) - { - break; - } - } - if (i == preambleLen) - { - _ps.bytePos = preambleLen; - } + // eat preamble + EatPreamble(); _documentStartBytePos = _ps.bytePos; @@ -3225,6 +3212,24 @@ namespace System.Xml } } + private void EatPreamble() + { + ReadOnlySpan<byte> preamble = _ps.encoding.Preamble; + int preambleLen = preamble.Length; + int i; + for (i = 0; i < preambleLen && i < _ps.bytesUsed; i++) + { + if (_ps.bytes[i] != preamble[i]) + { + break; + } + } + if (i == preambleLen) + { + _ps.bytePos = preambleLen; + } + } + // Switches the reader's encoding private void SwitchEncoding(Encoding newEncoding) { diff --git a/src/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplAsync.cs b/src/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplAsync.cs index 7cd3a428d0..4dc66f8de5 100644 --- a/src/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplAsync.cs +++ b/src/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplAsync.cs @@ -992,21 +992,8 @@ namespace System.Xml } SetupEncoding(encoding); - // eat preamble - byte[] preamble = _ps.encoding.GetPreamble(); - int preambleLen = preamble.Length; - int i; - for (i = 0; i < preambleLen && i < _ps.bytesUsed; i++) - { - if (_ps.bytes[i] != preamble[i]) - { - break; - } - } - if (i == preambleLen) - { - _ps.bytePos = preambleLen; - } + // eat preamble + EatPreamble(); _documentStartBytePos = _ps.bytePos; diff --git a/src/System.Private.Xml/src/System/Xml/Core/XmlUtf8RawTextWriter.cs b/src/System.Private.Xml/src/System/Xml/Core/XmlUtf8RawTextWriter.cs index 276b793cbe..f10d2efc56 100644 --- a/src/System.Private.Xml/src/System/Xml/Core/XmlUtf8RawTextWriter.cs +++ b/src/System.Private.Xml/src/System/Xml/Core/XmlUtf8RawTextWriter.cs @@ -125,10 +125,10 @@ namespace System.Xml // Output UTF-8 byte order mark if Encoding object wants it if (!stream.CanSeek || stream.Position == 0) { - byte[] bom = encoding.GetPreamble(); + ReadOnlySpan<byte> bom = encoding.Preamble; if (bom.Length != 0) { - Buffer.BlockCopy(bom, 0, bufBytes, 1, bom.Length); + bom.CopyTo(new Span<byte>(bufBytes, 1)); bufPos += bom.Length; textPos += bom.Length; } |