1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 20:42:21 +02:00

Proper MemMove

This commit is contained in:
Brian Fiete 2021-09-20 06:38:08 -07:00
parent 0dc45cb712
commit ce21b8d542
2 changed files with 7 additions and 6 deletions

View file

@ -277,7 +277,7 @@ namespace System
Debug.Assert(length >= 0);
Debug.Assert((uint)srcOffset + (uint)length <= (uint)mLength);
Debug.Assert((uint)dstOffset + (uint)length <= (uint)arrayTo.mLength);
Internal.MemCpy(&arrayTo.GetRef(dstOffset), &GetRef(srcOffset), strideof(T) * length, alignof(T));
Internal.MemMove(&arrayTo.GetRef(dstOffset), &GetRef(srcOffset), strideof(T) * length, alignof(T));
}
public void CopyTo<T2>(T2[] arrayTo, int srcOffset, int dstOffset, int length) where T2 : operator explicit T
@ -300,17 +300,18 @@ namespace System
public void CopyTo(Span<T> destination)
{
Debug.Assert(destination.[Friend]mLength >= mLength);
Internal.MemCpy(destination.Ptr, &GetRef(0), strideof(T) * mLength, alignof(T));
Internal.MemMove(destination.Ptr, &GetRef(0), strideof(T) * mLength, alignof(T));
}
public void CopyTo(Span<T> destination, int srcOffset)
{
Debug.Assert((uint)srcOffset + (uint)destination.[Friend]mLength <= (uint)mLength);
Internal.MemCpy(destination.Ptr, &GetRef(srcOffset), strideof(T) * (destination.[Friend]mLength - srcOffset), alignof(T));
Internal.MemMove(destination.Ptr, &GetRef(srcOffset), strideof(T) * (destination.[Friend]mLength - srcOffset), alignof(T));
}
public void CopyTo<T2>(Span<T2> destination, int srcOffset) where T2 : operator explicit T
{
//TODO: Handle src/dest overlap (MemMove)
Debug.Assert((uint)srcOffset + (uint)destination.[Friend]mLength <= (uint)mLength);
var ptr = destination.[Friend]mPtr;
for (int i = 0; i < destination.[Friend]mLength; i++)

View file

@ -535,7 +535,7 @@ namespace System.Collections
if (mSize == AllocSize) EnsureCapacity(mSize + 1, true);
if (index < mSize)
{
Internal.MemCpy(mItems + index + 1, mItems + index, (mSize - index) * strideof(T), alignof(T));
Internal.MemMove(mItems + index + 1, mItems + index, (mSize - index) * strideof(T), alignof(T));
}
mItems[index] = item;
mSize++;
@ -554,7 +554,7 @@ namespace System.Collections
if (mSize + addCount > AllocSize) EnsureCapacity(mSize + addCount, true);
if (index < mSize)
{
Internal.MemCpy(mItems + index + addCount, mItems + index, (mSize - index) * strideof(T), alignof(T));
Internal.MemMove(mItems + index + addCount, mItems + index, (mSize - index) * strideof(T), alignof(T));
}
Internal.MemCpy(mItems + index, items.Ptr, addCount * strideof(T));
mSize += (int_cosize)addCount;
@ -568,7 +568,7 @@ namespace System.Collections
Debug.Assert((uint)index < (uint)mSize);
if (index < mSize - 1)
{
Internal.MemCpy(mItems + index, mItems + index + 1, (mSize - index - 1) * strideof(T), alignof(T));
Internal.MemMove(mItems + index, mItems + index + 1, (mSize - index - 1) * strideof(T), alignof(T));
}
mSize--;
#if VERSION_LIST