Example #1
0
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// Thrown when the specified <paramref name="values"/>'s Length is longer than source span's Length.
        /// </exception>
        public void Set(ReadOnlySpan <T> values)
        {
            if ((uint)values.Length > (uint)_length)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException();
            }

            SpanHelper.CopyTo <T>(ref GetRawPointer(), ref values.GetRawPointer(), values.Length);
        }
Example #2
0
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// Thrown when the specified <paramref name="values"/>'s Length is longer than source span's Length.
        /// </exception>
        public void Set(ReadOnlySpan <T> values)
        {
            if ((uint)values.Length > (uint)_length)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException();
            }

            SpanHelper.CopyTo <T>(ref DangerousGetPinnableReference(), ref values.DangerousGetPinnableReference(), values.Length);
        }
Example #3
0
        /// <summary>
        /// Copies the contents of this span into destination span. If the source
        /// and destinations overlap, this method behaves as if the original values in
        /// a temporary location before the destination is overwritten.
        /// </summary>
        /// <param name="destination">The span to copy items into.</param>
        /// <returns>If the destination span is shorter than the source span, this method
        /// return false and no data is written to the destination.</returns>
        public bool TryCopyTo(Span <T> destination)
        {
            if ((uint)_length > (uint)destination.Length)
            {
                return(false);
            }

            SpanHelper.CopyTo <T>(ref destination._pointer.Value, ref _pointer.Value, _length);
            return(true);
        }
Example #4
0
        /// <summary>
        /// Copies the contents of this span into destination span. The destination
        /// must be at least as big as the source, and may be bigger.
        /// </summary>
        /// <param name="destination">The span to copy items into.</param>
        public bool TryCopyTo(Span <T> destination)
        {
            if ((uint)_length > (uint)destination.Length)
            {
                return(false);
            }

            SpanHelper.CopyTo <T>(ref destination.GetRawPointer(), ref GetRawPointer(), _length);
            return(true);
        }
Example #5
0
        /// <summary>
        /// Copies the contents of this span into destination span. The destination
        /// must be at least as big as the source, and may be bigger.
        /// </summary>
        /// <param name="destination">The span to copy items into.</param>
        public bool TryCopyTo(Span <T> destination)
        {
            if ((uint)_length > (uint)destination.Length)
            {
                return(false);
            }

            SpanHelper.CopyTo <T>(ref destination.DangerousGetPinnableReference(), ref DangerousGetPinnableReference(), _length);
            return(true);
        }
Example #6
0
File: Span.cs Project: xen2/coreclr
 public void Clear()
 {
     if (RuntimeHelpers.IsReferenceOrContainsReferences <T>())
     {
         SpanHelper.ClearWithReferences(ref Unsafe.As <T, IntPtr>(ref _pointer.Value), (nuint)_length * (nuint)(Unsafe.SizeOf <T>() / sizeof(nuint)));
     }
     else
     {
         SpanHelper.ClearWithoutReferences(ref Unsafe.As <T, byte>(ref _pointer.Value), (nuint)_length * (nuint)Unsafe.SizeOf <T>());
     }
 }
Example #7
0
        /// <summary>
        /// Copies the contents of this span into a new array.  This heap
        /// allocates, so should generally be avoided, however it is sometimes
        /// necessary to bridge the gap with APIs written in terms of arrays.
        /// </summary>
        public T[] ToArray()
        {
            if (_length == 0)
            {
                return(Array.Empty <T>());
            }

            var destination = new T[_length];

            SpanHelper.CopyTo <T>(ref JitHelpers.GetArrayData(destination), ref _pointer.Value, _length);
            return(destination);
        }
Example #8
0
        /// <summary>
        /// Copies the contents of this span into a new array.  This heap
        /// allocates, so should generally be avoided, however is sometimes
        /// necessary to bridge the gap with APIs written in terms of arrays.
        /// </summary>
        public T[] ToArray()
        {
            if (_length == 0)
            {
                return(Array.Empty <T>());
            }

            var destination = new T[_length];

            SpanHelper.CopyTo <T>(ref JitHelpers.GetArrayData(destination), ref DangerousGetPinnableReference(), _length);
            return(destination);
        }