public static void BlockCopy(Array src, int srcOffset, Array dest, int dstOffset, int count) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (dest == null) { throw new ArgumentNullException(nameof(dest)); } if (srcOffset < 0) { throw new ArgumentOutOfRangeException(nameof(srcOffset), SR.ArgumentOutOfRange_MustBeNonNegInt32); } if (dstOffset < 0) { throw new ArgumentOutOfRangeException(nameof(dstOffset), SR.ArgumentOutOfRange_MustBeNonNegInt32); } if (count < 0) { throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_MustBeNonNegInt32); } if (!IsPrimitiveTypeArray(src)) { throw new ArgumentException(SR.Arg_MustBePrimArray, nameof(src)); } if (!IsPrimitiveTypeArray(dest)) { throw new ArgumentException(SR.Arg_MustBePrimArray, nameof(dest)); } var uCount = (nuint)count; var uSrcOffset = (nuint)srcOffset; var uDstOffset = (nuint)dstOffset; var uSrcLen = (nuint)ByteLength(src); var uDstLen = (nuint)ByteLength(dest); if (uSrcLen < uSrcOffset + uCount) { throw new ArgumentException(SR.Argument_InvalidOffLen, ""); } if (uDstLen < uDstOffset + uCount) { throw new ArgumentException(SR.Argument_InvalidOffLen, ""); } if (uCount != 0) { unsafe { fixed(byte *pSrc = &src.GetRawArrayData(), pDst = &dest.GetRawArrayData()) { Memmove(pDst + uDstOffset, pSrc + uSrcOffset, uCount); } } } }
public static void SetByte(Array array, int index, byte value) { // array argument validation done via ByteLength if ((uint)index >= (uint)ByteLength(array)) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index); } Unsafe.Add <byte>(ref array.GetRawArrayData(), index) = value; }
public static byte GetByte(Array array, int index) { // array argument validation done via ByteLength if ((uint)index >= (uint)ByteLength(array)) { throw new ArgumentOutOfRangeException(nameof(index)); } return(Unsafe.Add <byte>(ref array.GetRawArrayData(), index)); }
public static unsafe void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count) { if (src == null) throw new ArgumentNullException(nameof(src)); if (dst == null) throw new ArgumentNullException(nameof(dst)); RuntimeImports.RhCorElementTypeInfo srcCorElementTypeInfo = src.ElementEEType.CorElementTypeInfo; nuint uSrcLen = ((nuint)src.Length) << srcCorElementTypeInfo.Log2OfSize; nuint uDstLen = uSrcLen; if (!srcCorElementTypeInfo.IsPrimitive) throw new ArgumentException(SR.Arg_MustBePrimArray, nameof(src)); if (src != dst) { RuntimeImports.RhCorElementTypeInfo dstCorElementTypeInfo = dst.ElementEEType.CorElementTypeInfo; if (!dstCorElementTypeInfo.IsPrimitive) throw new ArgumentException(SR.Arg_MustBePrimArray, nameof(dst)); uDstLen = ((nuint)dst.Length) << dstCorElementTypeInfo.Log2OfSize; } if (srcOffset < 0) throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_MustBeNonNegInt32, nameof(srcOffset)); if (dstOffset < 0) throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_MustBeNonNegInt32, nameof(dstOffset)); if (count < 0) throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_MustBeNonNegInt32, nameof(count)); nuint uCount = (nuint)count; if (uSrcLen < ((nuint)srcOffset) + uCount) throw new ArgumentException(SR.Argument_InvalidOffLen); if (uDstLen < ((nuint)dstOffset) + uCount) throw new ArgumentException(SR.Argument_InvalidOffLen); if (uCount == 0) return; fixed (byte* pSrc = &src.GetRawArrayData(), pDst = &dst.GetRawArrayData()) { Buffer.Memmove(pDst + dstOffset, pSrc + srcOffset, uCount); } }
public static unsafe void SetByte(Array array, int index, byte value) { // Is the array present? if (array == null) { throw new ArgumentNullException(nameof(array)); } // Is it of primitive types? if (!array.ElementEEType.IsPrimitive) { throw new ArgumentException(SR.Arg_MustBePrimArray, nameof(array)); } // Is the index in valid range of the array? if (index < 0 || index >= _ByteLength(array)) { throw new ArgumentOutOfRangeException(nameof(index)); } Unsafe.Add(ref array.GetRawArrayData(), index) = value; }
public static byte GetByte(Array array, int index) { // Is the array present? if (array == null) { throw new ArgumentNullException(nameof(array)); } // Is it of primitive types? if (!IsPrimitiveTypeArray(array)) { throw new ArgumentException(SR.Arg_MustBePrimArray, nameof(array)); } // Is the index in valid range of the array? if ((uint)index >= (uint)_ByteLength(array)) { throw new ArgumentOutOfRangeException(nameof(index)); } return(Unsafe.Add <byte>(ref array.GetRawArrayData(), index)); }
// Copies from one primitive array to another primitive array without // respecting types. This calls memmove internally. The count and // offset parameters here are in bytes. If you want to use traditional // array element indices and counts, use Array.Copy. public static unsafe void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (dst == null) { throw new ArgumentNullException(nameof(dst)); } nuint uSrcLen = (nuint)src.LongLength; if (src.GetType() != typeof(byte[])) { if (!src.GetCorElementTypeOfElementType().IsPrimitiveType()) { throw new ArgumentException(SR.Arg_MustBePrimArray, nameof(src)); } uSrcLen *= (nuint)src.GetElementSize(); } nuint uDstLen = uSrcLen; if (src != dst) { uDstLen = (nuint)dst.LongLength; if (dst.GetType() != typeof(byte[])) { if (!dst.GetCorElementTypeOfElementType().IsPrimitiveType()) { throw new ArgumentException(SR.Arg_MustBePrimArray, nameof(dst)); } uDstLen *= (nuint)dst.GetElementSize(); } } if (srcOffset < 0) { throw new ArgumentOutOfRangeException(nameof(srcOffset), SR.ArgumentOutOfRange_MustBeNonNegInt32); } if (dstOffset < 0) { throw new ArgumentOutOfRangeException(nameof(dstOffset), SR.ArgumentOutOfRange_MustBeNonNegInt32); } if (count < 0) { throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_MustBeNonNegInt32); } nuint uCount = (nuint)count; nuint uSrcOffset = (nuint)srcOffset; nuint uDstOffset = (nuint)dstOffset; if ((uSrcLen < uSrcOffset + uCount) || (uDstLen < uDstOffset + uCount)) { throw new ArgumentException(SR.Argument_InvalidOffLen); } Memmove(ref Unsafe.AddByteOffset(ref dst.GetRawArrayData(), uDstOffset), ref Unsafe.AddByteOffset(ref src.GetRawArrayData(), uSrcOffset), uCount); }
public static unsafe void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count) { nuint uSrcLen; nuint uDstLen; if (src == null) { throw new ArgumentNullException(nameof(src)); } if (dst == null) { throw new ArgumentNullException(nameof(dst)); } // Use optimized path for byte arrays since this is the main scenario for Buffer::BlockCopy // We only need an unreliable comparison since the slow path can handle the byte[] case too. if (src.EETypePtr.FastEqualsUnreliable(EETypePtr.EETypePtrOf <byte[]>())) { uSrcLen = (nuint)src.Length; } else { RuntimeImports.RhCorElementTypeInfo srcCorElementTypeInfo = src.ElementEEType.CorElementTypeInfo; uSrcLen = ((nuint)src.Length) << srcCorElementTypeInfo.Log2OfSize; if (!srcCorElementTypeInfo.IsPrimitive) { throw new ArgumentException(SR.Arg_MustBePrimArray, nameof(src)); } } if (src != dst) { // Use optimized path for byte arrays since this is the main scenario for Buffer::BlockCopy // We only need an unreliable comparison since the slow path can handle the byte[] case too. if (dst.EETypePtr.FastEqualsUnreliable(EETypePtr.EETypePtrOf <byte[]>())) { uDstLen = (nuint)dst.Length; } else { RuntimeImports.RhCorElementTypeInfo dstCorElementTypeInfo = dst.ElementEEType.CorElementTypeInfo; if (!dstCorElementTypeInfo.IsPrimitive) { throw new ArgumentException(SR.Arg_MustBePrimArray, nameof(dst)); } uDstLen = ((nuint)dst.Length) << dstCorElementTypeInfo.Log2OfSize; } } else { uDstLen = uSrcLen; } if (srcOffset < 0) { throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_MustBeNonNegInt32, nameof(srcOffset)); } if (dstOffset < 0) { throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_MustBeNonNegInt32, nameof(dstOffset)); } if (count < 0) { throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_MustBeNonNegInt32, nameof(count)); } nuint uCount = (nuint)count; nuint uSrcOffset = (nuint)srcOffset; nuint uDstOffset = (nuint)dstOffset; if (uSrcLen < uSrcOffset + uCount) { throw new ArgumentException(SR.Argument_InvalidOffLen); } if (uDstLen < uDstOffset + uCount) { throw new ArgumentException(SR.Argument_InvalidOffLen); } if (uCount != 0) { fixed(byte *pSrc = &src.GetRawArrayData(), pDst = &dst.GetRawArrayData()) { Buffer.Memmove(pDst + uDstOffset, pSrc + uSrcOffset, uCount); } } }
public static unsafe void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count) { if (src == null) { throw new ArgumentNullException(nameof(src)); } if (dst == null) { throw new ArgumentNullException(nameof(dst)); } RuntimeImports.RhCorElementTypeInfo srcCorElementTypeInfo = src.ElementEEType.CorElementTypeInfo; nuint uSrcLen = ((nuint)src.Length) << srcCorElementTypeInfo.Log2OfSize; nuint uDstLen = uSrcLen; if (!srcCorElementTypeInfo.IsPrimitive) { throw new ArgumentException(SR.Arg_MustBePrimArray, nameof(src)); } if (src != dst) { RuntimeImports.RhCorElementTypeInfo dstCorElementTypeInfo = dst.ElementEEType.CorElementTypeInfo; if (!dstCorElementTypeInfo.IsPrimitive) { throw new ArgumentException(SR.Arg_MustBePrimArray, nameof(dst)); } uDstLen = ((nuint)dst.Length) << dstCorElementTypeInfo.Log2OfSize; } if (srcOffset < 0) { throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_MustBeNonNegInt32, nameof(srcOffset)); } if (dstOffset < 0) { throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_MustBeNonNegInt32, nameof(dstOffset)); } if (count < 0) { throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_MustBeNonNegInt32, nameof(count)); } nuint uCount = (nuint)count; if (uSrcLen < ((nuint)srcOffset) + uCount) { throw new ArgumentException(SR.Argument_InvalidOffLen); } if (uDstLen < ((nuint)dstOffset) + uCount) { throw new ArgumentException(SR.Argument_InvalidOffLen); } if (uCount == 0) { return; fixed(byte *pSrc = &src.GetRawArrayData(), pDst = &dst.GetRawArrayData()) { Buffer.Memmove(pDst + dstOffset, pSrc + srcOffset, uCount); } }
public static unsafe void SetByte(Array array, int index, byte value) { // Is the array present? if (array == null) throw new ArgumentNullException(nameof(array)); // Is it of primitive types? if (!array.ElementEEType.IsPrimitive) throw new ArgumentException(SR.Arg_MustBePrimArray, nameof(array)); // Is the index in valid range of the array? if (index < 0 || index >= _ByteLength(array)) throw new ArgumentOutOfRangeException(nameof(index)); Unsafe.Add(ref array.GetRawArrayData(), index) = value; }
public static unsafe byte GetByte(Array array, int index) { // Is the array present? if (array == null) throw new ArgumentNullException("array"); // Is it of primitive types? if (!array.ElementEEType.IsPrimitive) throw new ArgumentException(SR.Arg_MustBePrimArray, "array"); // Is the index in valid range of the array? if (index < 0 || index >= _ByteLength(array)) throw new ArgumentOutOfRangeException("index"); return Unsafe.Add(ref array.GetRawArrayData(), index); }