Imported Upstream version 5.16.0.100

Former-commit-id: 38faa55fb9669e35e7d8448b15c25dc447f25767
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-08-07 15:19:03 +00:00
parent 0a9828183b
commit 7d7f676260
4419 changed files with 170950 additions and 90273 deletions

View File

@@ -220,7 +220,7 @@ namespace System.Text
}
// This constructor is needed to allow any sub-classing implementation to provide encoder/decoder fallback objects
// because the encoding object is always created as read-only object and don<EFBFBD>t allow setting encoder/decoder fallback
// because the encoding object is always created as read-only object and dont allow setting encoder/decoder fallback
// after the creation is done.
protected Encoding(int codePage, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
{
@@ -728,6 +728,10 @@ namespace System.Text
return EmptyArray<Byte>.Value;
}
#if MONO
public virtual ReadOnlySpan<byte> Preamble => GetPreamble();
#endif
private void GetDataItem() {
if (dataItem==null) {
dataItem = EncodingTable.GetCodePageDataItem(m_codePage);
@@ -995,6 +999,10 @@ namespace System.Text
[Pure]
public abstract int GetByteCount(char[] chars, int index, int count);
#if MONO
public int GetByteCount(string str, int index, int count) => GetByteCount(str.ToCharArray(), index, count);
#endif
// We expect this to be the workhorse for NLS encodings
// unfortunately for existing overrides, it has to call the [] version,
// which is really slow, so this method should be avoided if you're calling
@@ -1360,9 +1368,18 @@ namespace System.Text
}
#if MONO
public virtual unsafe int GetChars(ReadOnlySpan<byte> bytes, Span<char> chars)
{
fixed (byte* bytesPtr = &System.Runtime.InteropServices.MemoryMarshal.GetReference(bytes))
fixed (char* charsPtr = &System.Runtime.InteropServices.MemoryMarshal.GetReference(chars))
{
return GetChars(bytesPtr, bytes.Length, charsPtr, chars.Length);
}
}
public unsafe string GetString(ReadOnlySpan<byte> bytes)
{
fixed (byte* bytesPtr = &bytes.DangerousGetPinnableReference())
fixed (byte* bytesPtr = &bytes.GetPinnableReference())
{
return GetString(bytesPtr, bytes.Length);
}
@@ -1643,7 +1660,7 @@ namespace System.Text
[System.Security.SecurityCritical] // auto-generated
internal void ThrowBytesOverflow(EncoderNLS encoder, bool nothingEncoded)
{
if (encoder == null || encoder.m_throwOnOverflow || nothingEncoded)
if (encoder == null || encoder._throwOnOverflow || nothingEncoded)
{
if (encoder != null && encoder.InternalHasFallbackBuffer)
encoder.FallbackBuffer.InternalReset();
@@ -1668,7 +1685,7 @@ namespace System.Text
[System.Security.SecurityCritical] // auto-generated
internal void ThrowCharsOverflow(DecoderNLS decoder, bool nothingDecoded)
{
if (decoder == null || decoder.m_throwOnOverflow || nothingDecoded)
if (decoder == null || decoder._throwOnOverflow || nothingDecoded)
{
if (decoder != null && decoder.InternalHasFallbackBuffer)
decoder.FallbackBuffer.InternalReset();
@@ -1707,7 +1724,7 @@ namespace System.Text
try
{
this.m_fallback = (EncoderFallback) info.GetValue("m_fallback", typeof(EncoderFallback));
this._fallback = (EncoderFallback) info.GetValue("_fallback", typeof(EncoderFallback));
this.charLeftOver = (Char) info.GetValue("charLeftOver", typeof(Char));
}
catch (SerializationException)
@@ -1730,13 +1747,13 @@ namespace System.Text
}
Encoder encoder = m_encoding.GetEncoder();
if (m_fallback != null)
encoder.m_fallback = m_fallback;
if (_fallback != null)
encoder._fallback = _fallback;
if (charLeftOver != (char) 0)
{
EncoderNLS encoderNls = encoder as EncoderNLS;
if (encoderNls != null)
encoderNls.charLeftOver = charLeftOver;
encoderNls._charLeftOver = charLeftOver;
}
return encoder;
}
@@ -1835,11 +1852,11 @@ namespace System.Text
try
{
this.m_fallback = (DecoderFallback) info.GetValue("m_fallback", typeof(DecoderFallback));
this._fallback = (DecoderFallback) info.GetValue("_fallback", typeof(DecoderFallback));
}
catch (SerializationException)
{
m_fallback = null;
_fallback = null;
}
}
@@ -1858,8 +1875,8 @@ namespace System.Text
}
Decoder decoder = m_encoding.GetDecoder();
if (m_fallback != null)
decoder.m_fallback = m_fallback;
if (_fallback != null)
decoder._fallback = _fallback;
return decoder;
}
@@ -2174,7 +2191,7 @@ namespace System.Text
{
this.fallbackBuffer = this.encoder.FallbackBuffer;
// If we're not converting we must not have data in our fallback buffer
if (encoder.m_throwOnOverflow && encoder.InternalHasFallbackBuffer &&
if (encoder._throwOnOverflow && encoder.InternalHasFallbackBuffer &&
this.fallbackBuffer.Remaining > 0)
throw new ArgumentException(Environment.GetResourceString("Argument_EncoderFallbackNotEmpty",
encoder.Encoding.EncodingName, encoder.Fallback.GetType()));

View File

@@ -1889,7 +1889,22 @@ namespace System.Text {
}
}
}
#if !MONO
#if MONO
public StringBuilder Append(ReadOnlySpan<char> value)
{
if (value.Length > 0)
{
unsafe
{
fixed (char* valueChars = &MemoryMarshal.GetReference(value))
{
Append(valueChars, value.Length);
}
}
}
return this;
}
#else
// Copies the source StringBuilder to the destination IntPtr memory allocated with len bytes.
[System.Security.SecurityCritical] // auto-generated
internal unsafe void InternalCopy(IntPtr dest, int len) {