You've already forked linux-packaging-mono
Imported Upstream version 5.16.0.100
Former-commit-id: 38faa55fb9669e35e7d8448b15c25dc447f25767
This commit is contained in:
parent
0a9828183b
commit
7d7f676260
@ -476,12 +476,52 @@ namespace System {
|
||||
|
||||
#if MONO
|
||||
// Converts a Span into an int
|
||||
public static int ToInt32(ReadOnlySpan<byte> value)
|
||||
public static unsafe int ToInt32(ReadOnlySpan<byte> value)
|
||||
{
|
||||
if (value.Length < sizeof(int))
|
||||
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
|
||||
return Unsafe.ReadUnaligned<int>(ref value.DangerousGetPinnableReference());
|
||||
fixed (byte* bytesPtr = &value.GetPinnableReference())
|
||||
{
|
||||
return Unsafe.ReadUnaligned<int>(bytesPtr);
|
||||
}
|
||||
}
|
||||
|
||||
// Convert a Span into a uint
|
||||
[CLSCompliant(false)]
|
||||
public static unsafe uint ToUInt32(ReadOnlySpan<byte> value)
|
||||
{
|
||||
if (value.Length < sizeof(uint))
|
||||
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
|
||||
fixed (byte* bytesPtr = &value.GetPinnableReference())
|
||||
{
|
||||
return Unsafe.ReadUnaligned<uint>(bytesPtr);
|
||||
}
|
||||
}
|
||||
|
||||
// Converts a Span into an unsigned long
|
||||
[CLSCompliant(false)]
|
||||
public static unsafe ulong ToUInt64(ReadOnlySpan<byte> value)
|
||||
{
|
||||
if (value.Length < sizeof(ulong))
|
||||
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
|
||||
fixed (byte* bytesPtr = &value.GetPinnableReference())
|
||||
{
|
||||
return Unsafe.ReadUnaligned<ulong>(bytesPtr);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int SingleToInt32Bits(float value)
|
||||
{
|
||||
return *((int*)&value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe float Int32BitsToSingle(int value)
|
||||
{
|
||||
return *((float*)&value);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Security;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace System.Collections.Generic
|
||||
{
|
||||
@ -26,6 +27,7 @@ namespace System.Collections.Generic
|
||||
static volatile EqualityComparer<T> defaultComparer;
|
||||
|
||||
public static EqualityComparer<T> Default {
|
||||
[MethodImplAttribute (MethodImplOptions.AggressiveInlining)]
|
||||
get {
|
||||
Contract.Ensures(Contract.Result<EqualityComparer<T>>() != null);
|
||||
|
||||
@ -52,6 +54,10 @@ namespace System.Collections.Generic
|
||||
return (EqualityComparer<T>)(object)(new ByteEqualityComparer());
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// KEEP THIS IN SYNC WITH THE DEVIRT CODE
|
||||
// IN METHOD-TO-IR.C
|
||||
/////////////////////////////////////////////////
|
||||
#if MOBILE
|
||||
// Breaks .net serialization compatibility
|
||||
if (t == typeof (string))
|
||||
|
@ -86,6 +86,21 @@ namespace System {
|
||||
extern static object get_ephemeron_tombstone ();
|
||||
|
||||
internal static readonly object EPHEMERON_TOMBSTONE = get_ephemeron_tombstone ();
|
||||
|
||||
internal static void GetMemoryInfo(out uint highMemLoadThreshold,
|
||||
out ulong totalPhysicalMem,
|
||||
out uint lastRecordedMemLoad,
|
||||
// The next two are size_t
|
||||
out UIntPtr lastRecordedHeapSize,
|
||||
out UIntPtr lastRecordedFragmentation)
|
||||
{
|
||||
// TODO: Fill properly
|
||||
highMemLoadThreshold = 0;
|
||||
totalPhysicalMem = ulong.MaxValue;
|
||||
lastRecordedMemLoad = 0;
|
||||
lastRecordedHeapSize = UIntPtr.Zero;
|
||||
lastRecordedFragmentation = UIntPtr.Zero;
|
||||
}
|
||||
#else
|
||||
[System.Security.SecurityCritical] // auto-generated
|
||||
[ResourceExposure(ResourceScope.None)]
|
||||
|
@ -241,7 +241,7 @@ namespace System.Globalization {
|
||||
{
|
||||
return InternalTryFindStringOrdinalIgnoreCase(searchFlags, source, count, startIndex, value, value.Length, ref foundIndex);
|
||||
}
|
||||
#endif
|
||||
|
||||
// This function doesn't check arguments. Please do check in the caller.
|
||||
// The underlying unmanaged code will assert the sanity of arguments.
|
||||
[System.Security.SecuritySafeCritical] // auto-generated
|
||||
@ -252,7 +252,7 @@ namespace System.Globalization {
|
||||
// Compare the whole string and ignore case.
|
||||
return InternalCompareStringOrdinalIgnoreCase(str1, 0, str2, 0, str1.Length, str2.Length);
|
||||
}
|
||||
|
||||
#endif
|
||||
// This function doesn't check arguments. Please do check in the caller.
|
||||
// The underlying unmanaged code will assert the sanity of arguments.
|
||||
[System.Security.SecuritySafeCritical] // auto-generated
|
||||
|
@ -225,10 +225,26 @@ namespace System.IO {
|
||||
Contract.Requires(destination.CanWrite);
|
||||
Contract.Requires(bufferSize > 0);
|
||||
|
||||
#if MONO
|
||||
byte[] buffer = System.Buffers.ArrayPool<byte>.Shared.Rent(bufferSize);
|
||||
try
|
||||
{
|
||||
int read;
|
||||
while ((read = Read(buffer, 0, buffer.Length)) != 0)
|
||||
{
|
||||
destination.Write(buffer, 0, read);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
System.Buffers.ArrayPool<byte>.Shared.Return(buffer);
|
||||
}
|
||||
#else
|
||||
byte[] buffer = new byte[bufferSize];
|
||||
int read;
|
||||
while ((read = Read(buffer, 0, buffer.Length)) != 0)
|
||||
destination.Write(buffer, 0, read);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -62,7 +62,233 @@ namespace System {
|
||||
[ResourceExposure(ResourceScope.None)]
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
public static extern double Ceiling(double a);
|
||||
|
||||
|
||||
#if MONO
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static byte Clamp(byte value, byte min, byte max)
|
||||
{
|
||||
if (min > max)
|
||||
{
|
||||
ThrowMinMaxException(min, max);
|
||||
}
|
||||
|
||||
if (value < min)
|
||||
{
|
||||
return min;
|
||||
}
|
||||
else if (value > max)
|
||||
{
|
||||
return max;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static decimal Clamp(decimal value, decimal min, decimal max)
|
||||
{
|
||||
if (min > max)
|
||||
{
|
||||
ThrowMinMaxException(min, max);
|
||||
}
|
||||
|
||||
if (value < min)
|
||||
{
|
||||
return min;
|
||||
}
|
||||
else if (value > max)
|
||||
{
|
||||
return max;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double Clamp(double value, double min, double max)
|
||||
{
|
||||
if (min > max)
|
||||
{
|
||||
ThrowMinMaxException(min, max);
|
||||
}
|
||||
|
||||
if (value < min)
|
||||
{
|
||||
return min;
|
||||
}
|
||||
else if (value > max)
|
||||
{
|
||||
return max;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static short Clamp(short value, short min, short max)
|
||||
{
|
||||
if (min > max)
|
||||
{
|
||||
ThrowMinMaxException(min, max);
|
||||
}
|
||||
|
||||
if (value < min)
|
||||
{
|
||||
return min;
|
||||
}
|
||||
else if (value > max)
|
||||
{
|
||||
return max;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int Clamp(int value, int min, int max)
|
||||
{
|
||||
if (min > max)
|
||||
{
|
||||
ThrowMinMaxException(min, max);
|
||||
}
|
||||
|
||||
if (value < min)
|
||||
{
|
||||
return min;
|
||||
}
|
||||
else if (value > max)
|
||||
{
|
||||
return max;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static long Clamp(long value, long min, long max)
|
||||
{
|
||||
if (min > max)
|
||||
{
|
||||
ThrowMinMaxException(min, max);
|
||||
}
|
||||
|
||||
if (value < min)
|
||||
{
|
||||
return min;
|
||||
}
|
||||
else if (value > max)
|
||||
{
|
||||
return max;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
[CLSCompliant(false)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static sbyte Clamp(sbyte value, sbyte min, sbyte max)
|
||||
{
|
||||
if (min > max)
|
||||
{
|
||||
ThrowMinMaxException(min, max);
|
||||
}
|
||||
|
||||
if (value < min)
|
||||
{
|
||||
return min;
|
||||
}
|
||||
else if (value > max)
|
||||
{
|
||||
return max;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Clamp(float value, float min, float max)
|
||||
{
|
||||
if (min > max)
|
||||
{
|
||||
ThrowMinMaxException(min, max);
|
||||
}
|
||||
|
||||
if (value < min)
|
||||
{
|
||||
return min;
|
||||
}
|
||||
else if (value > max)
|
||||
{
|
||||
return max;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
[CLSCompliant(false)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ushort Clamp(ushort value, ushort min, ushort max)
|
||||
{
|
||||
if (min > max)
|
||||
{
|
||||
ThrowMinMaxException(min, max);
|
||||
}
|
||||
|
||||
if (value < min)
|
||||
{
|
||||
return min;
|
||||
}
|
||||
else if (value > max)
|
||||
{
|
||||
return max;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[CLSCompliant(false)]
|
||||
public static uint Clamp(uint value, uint min, uint max)
|
||||
{
|
||||
if (min > max)
|
||||
{
|
||||
ThrowMinMaxException(min, max);
|
||||
}
|
||||
|
||||
if (value < min)
|
||||
{
|
||||
return min;
|
||||
}
|
||||
else if (value > max)
|
||||
{
|
||||
return max;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[CLSCompliant(false)]
|
||||
public static ulong Clamp(ulong value, ulong min, ulong max)
|
||||
{
|
||||
if (min > max)
|
||||
{
|
||||
ThrowMinMaxException(min, max);
|
||||
}
|
||||
|
||||
if (value < min)
|
||||
{
|
||||
return min;
|
||||
}
|
||||
else if (value > max)
|
||||
{
|
||||
return max;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
#endif
|
||||
[System.Security.SecuritySafeCritical] // auto-generated
|
||||
[ResourceExposure(ResourceScope.None)]
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
@ -613,5 +839,11 @@ namespace System {
|
||||
result = a%b;
|
||||
return a/b;
|
||||
}
|
||||
#if MONO
|
||||
private static void ThrowMinMaxException<T>(T min, T max)
|
||||
{
|
||||
throw new ArgumentException(SR.Format(SR.Argument_MinMaxValue, min, max));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -710,7 +710,10 @@ namespace System.Runtime.CompilerServices
|
||||
/// <param name="result">The result for which we need a task.</param>
|
||||
/// <returns>The completed task containing the result.</returns>
|
||||
[SecuritySafeCritical] // for JitHelpers.UnsafeCast
|
||||
private Task<TResult> GetTaskForResult(TResult result)
|
||||
#if MONO
|
||||
internal static
|
||||
#endif
|
||||
Task<TResult> GetTaskForResult(TResult result)
|
||||
{
|
||||
Contract.Ensures(
|
||||
EqualityComparer<TResult>.Default.Equals(result, Contract.Result<Task<TResult>>().Result),
|
||||
@ -775,7 +778,9 @@ namespace System.Runtime.CompilerServices
|
||||
(typeof(TResult) == typeof(Byte) && default(Byte) == (Byte)(object)result) ||
|
||||
(typeof(TResult) == typeof(SByte) && default(SByte) == (SByte)(object)result) ||
|
||||
(typeof(TResult) == typeof(Char) && default(Char) == (Char)(object)result) ||
|
||||
#if !MONO
|
||||
(typeof(TResult) == typeof(Decimal) && default(Decimal) == (Decimal)(object)result) ||
|
||||
#endif
|
||||
(typeof(TResult) == typeof(Int64) && default(Int64) == (Int64)(object)result) ||
|
||||
(typeof(TResult) == typeof(UInt64) && default(UInt64) == (UInt64)(object)result) ||
|
||||
(typeof(TResult) == typeof(Int16) && default(Int16) == (Int16)(object)result) ||
|
||||
|
@ -1338,4 +1338,4 @@ namespace System.Runtime.InteropServices.WindowsRuntime
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -49,14 +49,12 @@ namespace System {
|
||||
|
||||
[Pure]
|
||||
[System.Security.SecuritySafeCritical] // auto-generated
|
||||
[System.Runtime.Versioning.NonVersionable]
|
||||
public unsafe static bool IsInfinity(float f) {
|
||||
return (*(int*)(&f) & 0x7FFFFFFF) == 0x7F800000;
|
||||
}
|
||||
|
||||
[Pure]
|
||||
[System.Security.SecuritySafeCritical] // auto-generated
|
||||
[System.Runtime.Versioning.NonVersionable]
|
||||
public unsafe static bool IsPositiveInfinity(float f) {
|
||||
return *(int*)(&f) == 0x7F800000;
|
||||
}
|
||||
@ -78,11 +76,19 @@ namespace System {
|
||||
|
||||
#if MONO
|
||||
[Pure]
|
||||
[System.Runtime.Versioning.NonVersionable]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe static bool IsFinite(float f) {
|
||||
return (*(int*)(&f) & 0x7FFFFFFF) < 0x7F800000;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe bool IsNegative(float f)
|
||||
{
|
||||
var bits = unchecked((uint)BitConverter.SingleToInt32Bits(f));
|
||||
return (bits & 0x80000000) == 0x80000000;
|
||||
}
|
||||
internal const float NegativeZero = (float)-0.0;
|
||||
|
||||
#endif
|
||||
|
||||
// Compares this object to another object, returning an integer that
|
||||
|
@ -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 don’t 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()));
|
||||
|
@ -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) {
|
||||
|
@ -79,6 +79,9 @@ namespace System.Threading
|
||||
// A pre-completed task with Result==true
|
||||
private readonly static Task<bool> s_trueTask =
|
||||
new Task<bool>(false, true, (TaskCreationOptions)InternalTaskOptions.DoNotDispose, default(CancellationToken));
|
||||
// A pre-completed task with Result==false
|
||||
private readonly static Task<bool> s_falseTask =
|
||||
new Task<bool>(false, false, (TaskCreationOptions)InternalTaskOptions.DoNotDispose, default(CancellationToken));
|
||||
|
||||
// No maximum constant
|
||||
private const int NO_MAXIMUM = Int32.MaxValue;
|
||||
@ -323,6 +326,13 @@ namespace System.Threading
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
// Perf: Check the stack timeout parameter before checking the volatile count
|
||||
if (millisecondsTimeout == 0 && m_currentCount == 0)
|
||||
{
|
||||
// Pessimistic fail fast, check volatile count outside lock (only when timeout is zero!)
|
||||
return false;
|
||||
}
|
||||
|
||||
uint startTime = 0;
|
||||
if (millisecondsTimeout != Timeout.Infinite && millisecondsTimeout > 0)
|
||||
{
|
||||
@ -620,6 +630,11 @@ namespace System.Threading
|
||||
--m_currentCount;
|
||||
if (m_waitHandle != null && m_currentCount == 0) m_waitHandle.Reset();
|
||||
return s_trueTask;
|
||||
}
|
||||
else if (millisecondsTimeout == 0)
|
||||
{
|
||||
// No counts, if timeout is zero fail fast
|
||||
return s_falseTask;
|
||||
}
|
||||
// If there aren't, create and return a task to the caller.
|
||||
// The task will be completed either when they've successfully acquired
|
||||
|
@ -187,6 +187,48 @@ namespace System {
|
||||
{
|
||||
throw GetKeyNotFoundException(key);
|
||||
}
|
||||
|
||||
internal static void ThrowInvalidTypeWithPointersNotSupported(Type targetType)
|
||||
{
|
||||
throw new ArgumentException(SR.Format(SR.Argument_InvalidTypeWithPointersNotSupported, targetType));
|
||||
}
|
||||
|
||||
internal static void ThrowInvalidOperationException_ConcurrentOperationsNotSupported()
|
||||
{
|
||||
throw GetInvalidOperationException("Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.");
|
||||
}
|
||||
|
||||
internal static InvalidOperationException GetInvalidOperationException(string str)
|
||||
{
|
||||
return new InvalidOperationException(str);
|
||||
}
|
||||
|
||||
internal static void ThrowArraySegmentCtorValidationFailedExceptions(Array array, int offset, int count)
|
||||
{
|
||||
throw GetArraySegmentCtorValidationFailedException(array, offset, count);
|
||||
}
|
||||
|
||||
private static Exception GetArraySegmentCtorValidationFailedException(Array array, int offset, int count)
|
||||
{
|
||||
if (array == null)
|
||||
return GetArgumentNullException(ExceptionArgument.array);
|
||||
if (offset < 0)
|
||||
return GetArgumentOutOfRangeException(ExceptionArgument.offset, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
|
||||
if (count < 0)
|
||||
return GetArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
|
||||
|
||||
return GetArgumentException(ExceptionResource.Argument_InvalidOffLen);
|
||||
}
|
||||
|
||||
private static ArgumentException GetArgumentException(ExceptionResource resource)
|
||||
{
|
||||
return new ArgumentException(resource.ToString());
|
||||
}
|
||||
|
||||
private static ArgumentNullException GetArgumentNullException(ExceptionArgument argument)
|
||||
{
|
||||
return new ArgumentNullException(GetArgumentName(argument));
|
||||
}
|
||||
#endif
|
||||
|
||||
// Allow nulls for reference types and Nullable<U>, but not for value types.
|
||||
@ -566,7 +608,20 @@ namespace System {
|
||||
exceptions,
|
||||
exception,
|
||||
action,
|
||||
comparison
|
||||
comparison,
|
||||
startSegment,
|
||||
endSegment,
|
||||
endIndex,
|
||||
task,
|
||||
source,
|
||||
state,
|
||||
culture,
|
||||
destination,
|
||||
byteOffset,
|
||||
minimumBufferSize,
|
||||
offset,
|
||||
values,
|
||||
comparisonType,
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -625,6 +680,8 @@ namespace System {
|
||||
TaskT_TransitionToFinal_AlreadyCompleted,
|
||||
TaskCompletionSourceT_TrySetException_NullException,
|
||||
TaskCompletionSourceT_TrySetException_NoExceptions,
|
||||
NotSupported_StringComparison,
|
||||
InvalidOperation_NullArray,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -379,6 +379,26 @@ namespace System {
|
||||
return t1._ticks >= t2._ticks;
|
||||
}
|
||||
|
||||
public static TimeSpan operator / (TimeSpan timeSpan, double divisor)
|
||||
{
|
||||
if (double.IsNaN (divisor)) {
|
||||
throw new ArgumentException (SR.Arg_CannotBeNaN, nameof (divisor));
|
||||
}
|
||||
|
||||
double ticks = Math.Round (timeSpan.Ticks / divisor);
|
||||
if (ticks > long.MaxValue | ticks < long.MinValue || double.IsNaN (ticks)) {
|
||||
throw new OverflowException (SR.Overflow_TimeSpanTooLong);
|
||||
}
|
||||
|
||||
return FromTicks ((long)ticks);
|
||||
}
|
||||
|
||||
// Using floating-point arithmetic directly means that infinities can be returned, which is reasonable
|
||||
// if we consider TimeSpan.FromHours(1) / TimeSpan.Zero asks how many zero-second intervals there are in
|
||||
// an hour for which infinity is the mathematic correct answer. Having TimeSpan.Zero / TimeSpan.Zero return NaN
|
||||
// is perhaps less useful, but no less useful than an exception.
|
||||
public static double operator /(TimeSpan t1, TimeSpan t2) => t1.Ticks / (double)t2.Ticks;
|
||||
|
||||
|
||||
//
|
||||
// In .NET Framework v1.0 - v3.5 System.TimeSpan did not implement IFormattable
|
||||
|
Reference in New Issue
Block a user