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:
parent
301f9eb1c1
commit
e7912b1095
3 changed files with 14 additions and 15 deletions
|
@ -290,23 +290,15 @@ namespace System.Collections
|
|||
}
|
||||
}
|
||||
|
||||
public void CopyTo(KeyValuePair[] kvPair, int index)
|
||||
public void CopyTo(Span<KeyValuePair> kvPair)
|
||||
{
|
||||
Keys.Reset();
|
||||
Values.Reset();
|
||||
int i = 0;
|
||||
|
||||
repeat
|
||||
Debug.Assert(kvPair.Length >= mCount);
|
||||
int idx = 0;
|
||||
for (var kv in this)
|
||||
{
|
||||
if (i >= index)
|
||||
{
|
||||
kvPair[i] = (Keys.Current, Values.Current);
|
||||
}
|
||||
kvPair[idx] = kv;
|
||||
++idx;
|
||||
}
|
||||
while(Keys.MoveNext() && Values.MoveNext());
|
||||
|
||||
Keys.Reset();
|
||||
Values.Reset();
|
||||
}
|
||||
|
||||
public Enumerator GetEnumerator()
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace System.Collections
|
|||
public void Add(T item);
|
||||
public void Clear();
|
||||
public bool Contains(T item);
|
||||
public void CopyTo(T[] arr, int index);
|
||||
public void CopyTo(Span<T> span);
|
||||
public bool Remove(T item);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -403,6 +403,13 @@ namespace System.Collections
|
|||
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)
|
||||
{
|
||||
// Delegate rest of error checking to Array.Copy.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue