1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +02:00

Made CopyTo use Span

This commit is contained in:
Brian Fiete 2021-01-05 05:56:11 -08:00
parent 301f9eb1c1
commit e7912b1095
3 changed files with 14 additions and 15 deletions

View file

@ -290,23 +290,15 @@ namespace System.Collections
} }
} }
public void CopyTo(KeyValuePair[] kvPair, int index) public void CopyTo(Span<KeyValuePair> kvPair)
{ {
Keys.Reset(); Debug.Assert(kvPair.Length >= mCount);
Values.Reset(); int idx = 0;
int i = 0; for (var kv in this)
repeat
{ {
if (i >= index) kvPair[idx] = kv;
{ ++idx;
kvPair[i] = (Keys.Current, Values.Current);
}
} }
while(Keys.MoveNext() && Values.MoveNext());
Keys.Reset();
Values.Reset();
} }
public Enumerator GetEnumerator() public Enumerator GetEnumerator()

View file

@ -10,7 +10,7 @@ namespace System.Collections
public void Add(T item); public void Add(T item);
public void Clear(); public void Clear();
public bool Contains(T item); public bool Contains(T item);
public void CopyTo(T[] arr, int index); public void CopyTo(Span<T> span);
public bool Remove(T item); public bool Remove(T item);
} }
} }

View file

@ -403,6 +403,13 @@ namespace System.Collections
Internal.MemCpy(destList.mItems, mItems, mSize * strideof(T), alignof(T)); Internal.MemCpy(destList.mItems, mItems, mSize * strideof(T), alignof(T));
} }
public void CopyTo(Span<T> span)
{
// Delegate rest of error checking to Array.Copy.
for (int i = 0; i < mSize; i++)
span[i] = mItems[i];
}
public void CopyTo(T[] array, int arrayIndex) public void CopyTo(T[] array, int arrayIndex)
{ {
// Delegate rest of error checking to Array.Copy. // Delegate rest of error checking to Array.Copy.