Ejemplo n.º 1
0
        /// <summary>
        /// Implements the copy functionality used by Span and ReadOnlySpan.
        ///
        /// NOTE: Fast span implements TryCopyTo in corelib and therefore this implementation
        ///       is only used by portable span. The code must live in code that only compiles
        ///       for portable span which means either each individual span implementation
        ///       of this shared code file. Other shared SpanHelper.X.cs files are compiled
        ///       for both portable and fast span implementations.
        /// </summary>
        public static unsafe void CopyTo <T>(ref T dst, int dstLength, ref T src, int srcLength)
        {
            Debug.Assert(dstLength != 0);

            IntPtr srcByteCount = Unsafe.ByteOffset(ref src, ref Unsafe.Add(ref src, srcLength));
            IntPtr dstByteCount = Unsafe.ByteOffset(ref dst, ref Unsafe.Add(ref dst, dstLength));

            IntPtr diff = Unsafe.ByteOffset(ref src, ref dst);

            bool isOverlapped = (sizeof(IntPtr) == sizeof(int))
                ? (uint)diff <(uint)srcByteCount || (uint)diff> (uint) - (int)dstByteCount
                : (ulong)diff <(ulong)srcByteCount || (ulong)diff> (ulong) - (long)dstByteCount;

            if (!isOverlapped && !VecHelpers.IsReferenceOrContainsReferences <T>())
            {
                ref byte dstBytes  = ref Unsafe.As <T, byte>(ref dst);
                ref byte srcBytes  = ref Unsafe.As <T, byte>(ref src);
Ejemplo n.º 2
0
 public static bool IsReferenceOrContainsReferences <T>()
 {
     return(VecHelpers.IsReferenceOrContainsReferences <T>());
 }