Ejemplo n.º 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;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 9
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 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;
        }
Ejemplo n.º 10
0
        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;
        }
Ejemplo n.º 11
0
Archivo: Span.cs Proyecto: 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;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 15
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 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;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
        }