示例#1
0
        public Span(T[]?array)
        {
            if (array == null)
            {
                this = default;
                return;                                                 // returns default
            }
            if (default(T) ! == null && array.GetType() != typeof(T[])) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
            {
                ThrowHelper.ThrowArrayTypeMismatchException();
            }

            _pointer = new ByReference <T>(ref MemoryMarshal.GetArrayDataReference(array));
            _length  = array.Length;
        }
示例#2
0
        public Span(T[]?array)
        {
            if (array == null)
            {
                this = default;
                return;                                                 // returns default
            }
            if (default(T) ! == null && array.GetType() != typeof(T[])) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34757
            {
                ThrowHelper.ThrowArrayTypeMismatchException();
            }

            _pointer = new ByReference <T>(ref Unsafe.As <byte, T>(ref array.GetRawSzArrayData()));
            _length  = array.Length;
        }
示例#3
0
        public Span(T[] array)
        {
            if (array == null)
            {
                this = default;
                return; // returns default
            }
            if (default(T) == null && array.GetType() != typeof(T[]))
            {
                ThrowHelper.ThrowArrayTypeMismatchException();
            }

            _pointer = new ByReference <T>(ref Unsafe.As <byte, T>(ref array.GetRawSzArrayData()));
            _length  = array.Length;
        }
示例#4
0
文件: Span.cs 项目: z77ma/runtime
        public Span(T[]?array)
        {
            if (array == null)
            {
                this = default;
                return; // returns default
            }
            if (!typeof(T).IsValueType && array.GetType() != typeof(T[]))
            {
                ThrowHelper.ThrowArrayTypeMismatchException();
            }

            _pointer = new ByReference <T>(ref MemoryMarshal.GetArrayDataReference(array));
            _length  = array.Length;
        }
示例#5
0
        public Memory(T[] array)
        {
            if (array == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
            }
            if (default(T) == null && array.GetType() != typeof(T[]))
            {
                ThrowHelper.ThrowArrayTypeMismatchException();
            }

            _arrayOrOwnedMemory = array;
            _index  = 0;
            _length = array.Length;
        }
示例#6
0
        public Span(T[] array)
        {
            if (array == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
            }
            if (default(T) == null && array.GetType() != typeof(T[]))
            {
                ThrowHelper.ThrowArrayTypeMismatchException();
            }

            _length     = array.Length;
            _pinnable   = Unsafe.As <Pinnable <T> >(array);
            _byteOffset = SpanHelpers.PerTypeValues <T> .ArrayAdjustment;
        }
示例#7
0
        public Memory(T[] array)
        {
            if (array == null)
            {
                this = default;
                return; // returns default
            }
            if (default(T) == null && array.GetType() != typeof(T[]))
            {
                ThrowHelper.ThrowArrayTypeMismatchException();
            }

            _object = array;
            _index  = 0;
            _length = array.Length;
        }
示例#8
0
        public Memory(T[]?array)
        {
            if (array == null)
            {
                this = default;
                return;                                                 // returns default
            }
            if (default(T) ! == null && array.GetType() != typeof(T[])) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34757
            {
                ThrowHelper.ThrowArrayTypeMismatchException();
            }

            _object = array;
            _index  = 0;
            _length = array.Length;
        }
示例#9
0
文件: Span.cs 项目: etad4e5/coreclr
        /// <summary>
        /// Creates a new span over the entirety of the target array.
        /// </summary>
        /// <param name="array">The target array.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="array"/> is a null
        /// reference (Nothing in Visual Basic).</exception>
        /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="array"/> is covariant and array's type is not exactly T[].</exception>
        public Span(T[] array)
        {
            if (array == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
            }
            if (default(T) == null)   // Arrays of valuetypes are never covariant
            {
                if (array.GetType() != typeof(T[]))
                {
                    ThrowHelper.ThrowArrayTypeMismatchException();
                }
            }

            _pointer = new ByReference <T>(ref JitHelpers.GetArrayData(array));
            _length  = array.Length;
        }
示例#10
0
文件: Span.cs 项目: anydream/coreclr
        public Span(T[] array, int start, int length)
        {
            if (array == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
            }
            if (default(T) == null && array.GetInternalTypeID() != RuntimeHelpers.GetInternalTypeID <T[]>())
            {
                ThrowHelper.ThrowArrayTypeMismatchException();
            }
            if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start))
            {
                ThrowHelper.ThrowArgumentOutOfRangeException();
            }

            _pointer = new ByReference <T>(ref Unsafe.Add(ref Unsafe.As <byte, T>(ref array.GetRawSzArrayData()), start));
            _length  = length;
        }
示例#11
0
文件: Span.cs 项目: xen2/coreclr
        public Span(T[] array, int start)
        {
            if (array == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
            }
            if (default(T) == null && array.GetType() != typeof(T[]))
            {
                ThrowHelper.ThrowArrayTypeMismatchException();
            }
            if ((uint)start > (uint)array.Length)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException();
            }

            _pointer = new ByReference <T>(ref Unsafe.Add(ref JitHelpers.GetArrayData(array), start));
            _length  = array.Length - start;
        }
示例#12
0
        /// <summary>
        /// Creates a new span over the entirety of the target array.
        /// </summary>
        /// <param name="array">The target array.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="array"/> is a null
        /// reference (Nothing in Visual Basic).</exception>
        /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="array"/> is covariant.</exception>
        public Span(T[] array)
        {
            if (array == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
            }
            if (default(T) == null)   // Arrays of valuetypes are never covariant
            {
                if (array.GetType() != typeof(T[]))
                {
                    ThrowHelper.ThrowArrayTypeMismatchException();
                }
            }

            // TODO-SPAN: This has GC hole. It needs to be JIT intrinsic instead
            _rawPointer = (IntPtr)Unsafe.AsPointer(ref JitHelpers.GetArrayData(array));
            _length     = array.Length;
        }
示例#13
0
        public Span(T[] array, int start, int length)
        {
            if (array == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
            }
            if (default(T) == null && array.GetType() != typeof(T[]))
            {
                ThrowHelper.ThrowArrayTypeMismatchException();
            }
            if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start))
            {
                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start);
            }

            _length     = length;
            _pinnable   = Unsafe.As <Pinnable <T> >(array);
            _byteOffset = SpanHelpers.PerTypeValues <T> .ArrayAdjustment.Add <T>(start);
        }
示例#14
0
        public Memory(T[] array, int start, int length)
        {
            if (array == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
            }
            if (default(T) == null && array.GetType() != typeof(T[]))
            {
                ThrowHelper.ThrowArrayTypeMismatchException();
            }
            if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start))
            {
                ThrowHelper.ThrowArgumentOutOfRangeException();
            }

            _object = array;
            _index  = start;
            _length = length;
        }
示例#15
0
文件: Span.cs 项目: etad4e5/coreclr
        /// <summary>
        /// Creates a new span over the portion of the target array beginning
        /// at 'start' index and ending at 'end' index (exclusive).
        /// </summary>
        /// <param name="array">The target array.</param>
        /// <param name="start">The index at which to begin the span.</param>
        /// <param name="length">The number of items in the span.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="array"/> is a null
        /// reference (Nothing in Visual Basic).</exception>
        /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="array"/> is covariant and array's type is not exactly T[].</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// Thrown when the specified <paramref name="start"/> or end index is not in the range (&lt;0 or &gt;=Length).
        /// </exception>
        public Span(T[] array, int start, int length)
        {
            if (array == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
            }
            if (default(T) == null)   // Arrays of valuetypes are never covariant
            {
                if (array.GetType() != typeof(T[]))
                {
                    ThrowHelper.ThrowArrayTypeMismatchException();
                }
            }
            if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start))
            {
                ThrowHelper.ThrowArgumentOutOfRangeException();
            }

            _pointer = new ByReference <T>(ref Unsafe.Add(ref JitHelpers.GetArrayData(array), start));
            _length  = length;
        }
示例#16
0
        /// <summary>
        /// Creates a new span over the portion of the target array beginning
        /// at 'start' index and ending at 'end' index (exclusive).
        /// </summary>
        /// <param name="array">The target array.</param>
        /// <param name="start">The index at which to begin the span.</param>
        /// <param name="length">The number of items in the span.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="array"/> is a null
        /// reference (Nothing in Visual Basic).</exception>
        /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="array"/> is covariant.</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// Thrown when the specified <paramref name="start"/> or end index is not in range (&lt;0 or &gt;&eq;Length).
        /// </exception>
        public Span(T[] array, int start, int length)
        {
            if (array == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
            }
            if (default(T) == null)   // Arrays of valuetypes are never covariant
            {
                if (array.GetType() != typeof(T[]))
                {
                    ThrowHelper.ThrowArrayTypeMismatchException();
                }
            }
            if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start))
            {
                ThrowHelper.ThrowArgumentOutOfRangeException();
            }

            // TODO-SPAN: This has GC hole. It needs to be JIT intrinsic instead
            _rawPointer = (IntPtr)Unsafe.AsPointer(ref Unsafe.Add(ref JitHelpers.GetArrayData(array), start));
            _length     = length;
        }
示例#17
0
        public Span(T[] array, int start, int length)
        {
            if (array == null)
            {
                if (start != 0 || length != 0)
                {
                    ThrowHelper.ThrowArgumentOutOfRangeException();
                }
                this = default;
                return; // returns default
            }
            if (default(T) == null && array.GetType() != typeof(T[]))
            {
                ThrowHelper.ThrowArrayTypeMismatchException();
            }
            if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start))
            {
                ThrowHelper.ThrowArgumentOutOfRangeException();
            }

            _pointer = new ByReference <T>(ref Unsafe.Add(ref Unsafe.As <byte, T>(ref array.GetRawSzArrayData()), start));
            _length  = length;
        }
示例#18
0
        internal Memory(T[] array, int start)
        {
            if (array == null)
            {
                if (start != 0)
                {
                    ThrowHelper.ThrowArgumentOutOfRangeException();
                }
                this = default;
                return; // returns default
            }
            if (default(T) == null && array.GetType() != typeof(T[]))
            {
                ThrowHelper.ThrowArrayTypeMismatchException();
            }
            if ((uint)start > (uint)array.Length)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException();
            }

            _object = array;
            _index  = start;
            _length = array.Length - start;
        }
示例#19
0
        internal Memory(T[]?array, int start)
        {
            if (array == null)
            {
                if (start != 0)
                {
                    ThrowHelper.ThrowArgumentOutOfRangeException();
                }
                this = default;
                return;                                                 // returns default
            }
            if (default(T) ! == null && array.GetType() != typeof(T[])) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34757
            {
                ThrowHelper.ThrowArrayTypeMismatchException();
            }
            if ((uint)start > (uint)array.Length)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException();
            }

            _object = array;
            _index  = start;
            _length = array.Length - start;
        }