Пример #1
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();
            }

            _pointer = new ByReference <T>(ref Unsafe.Add(ref JitHelpers.GetArrayData(array), start));
            _length  = length;
        }
Пример #2
0
        /// <summary>
        /// Creates a new span over the portion of the target array beginning
        /// at 'start' index and covering the remainder of the array.
        /// </summary>
        /// <param name="array">The target array.</param>
        /// <param name="start">The index at which to begin 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"/> is not in the range (&lt;0 or &gt;=Length).
        /// </exception>
        public Span(T[] array, int start)
        {
            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)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException();
            }

            _pointer = new ByReference <T>(ref Unsafe.Add(ref JitHelpers.GetArrayData(array), start));
            _length  = array.Length - start;
        }
Пример #3
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;
        }
Пример #4
0
 /// <summary>
 /// Creates a new span over the entirety of the target array.
 /// </summary>
 /// <param name="array">The target array.</param>
 public ReadOnlySpan(T[] array)
 {
     JitHelpers.SetByRef(out _rawPointer, ref JitHelpers.GetArrayData(array));
     _length = array.Length;
 }