Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Simplify Array.Copy(a, 0, b, 0, c) to Array.Copy(a, b, c) #42343

Merged
merged 1 commit into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static SafeBCryptAlgorithmHandle GetCachedBCryptAlgorithmHandle(string ha

Entry[] newCache = new Entry[cache.Length + 1];
Entry newEntry = new Entry(hashAlgorithmId, flags, safeBCryptAlgorithmHandle);
Array.Copy(cache, 0, newCache, 0, cache.Length);
Array.Copy(cache, newCache, cache.Length);
newCache[newCache.Length - 1] = newEntry;

// Atomically overwrite the cache with our new cache. It's possible some other thread raced to add a new entry with us - if so, one of the new entries
Expand Down
4 changes: 2 additions & 2 deletions src/Common/src/System/Collections/Generic/ArrayBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public T[] ToArray()
// Avoid a bit of overhead (method call, some branches, extra codegen)
// which would be incurred by using Array.Resize
result = new T[_count];
Array.Copy(_array, 0, result, 0, _count);
Array.Copy(_array, result, _count);
}

#if DEBUG
Expand Down Expand Up @@ -156,7 +156,7 @@ private void EnsureCapacity(int minimum)
T[] next = new T[nextCapacity];
if (_count > 0)
{
Array.Copy(_array!, 0, next, 0, _count);
Array.Copy(_array!, next, _count);
}
_array = next;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private void AllocateBuffer()
int nextCapacity = Math.Min(_count == 0 ? StartingCapacity : _count * 2, _maxCapacity);

_current = new T[nextCapacity];
Array.Copy(_first, 0, _current, 0, _count);
Array.Copy(_first, _current, _count);
_first = _current;
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/Common/tests/StaticTestGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ void WriteArgumentListStatic(object[]? arguments, ParameterInfo[] parameters)
else if (arguments.Length < parameters.Length)
{
var newArguments = new object[parameters.Length];
Array.Copy(arguments, 0, newArguments, 0, arguments.Length);
Array.Copy(arguments, newArguments, arguments.Length);
for (int i = arguments.Length; i < parameters.Length; i++)
{
if (parameters[i].HasDefaultValue)
Expand Down
8 changes: 4 additions & 4 deletions src/Common/tests/System/Collections/IListTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ public void AddWithNullValueInMiddle()
items = new object[sizeWithNull];
list.Add(null);
items[sizeWithNull/2] = null;
Array.Copy(tempItems, 0, items, 0, sizeWithNull/2);
Array.Copy(tempItems, items, sizeWithNull/2);
Array.Copy(
tempItems,
sizeWithNull/2,
Expand Down Expand Up @@ -567,7 +567,7 @@ public void AddDuplicateValue()
list.AddRange(tempItems);
list.AddRange(tempItems);

Array.Copy(tempItems, 0, items, 0, 16);
Array.Copy(tempItems, items, 16);
Array.Copy(tempItems, 0, items, 16, 16);
}
CollectionAssert.Equal(items, list);
Expand Down Expand Up @@ -1311,7 +1311,7 @@ public void InsertAndRemove()
{
object newObject = GenerateItem();
list.Insert(i, newObject);
Array.Copy(items, 0, tempItems, 0, i);
Array.Copy(items, tempItems, i);
tempItems[i] = newObject;
Array.Copy(items, i, tempItems, i + 1, items.Length - i);
CollectionAssert.Equal(tempItems, list);
Expand Down Expand Up @@ -1533,7 +1533,7 @@ public void RemoveNull()
IList list = GetList(null);
object[] tempItems = GenerateItems(16);
list.AddRange(tempItems);
Array.Copy(tempItems, 0, items, 0, 11);
Array.Copy(tempItems, items, 11);
Array.Copy(tempItems, 12, items, 11, 4);
list.Insert(8, null);
list.Remove(tempItems[11]);
Expand Down
2 changes: 1 addition & 1 deletion src/Common/tests/System/Collections/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static T[] Push<T>(this T[] array, params T[] arguments)
public static T[] RemoveAt<T>(this T[] array, int removeIndex)
{
var ret = new T[array.Length - 1];
Array.Copy(array, 0, ret, 0, removeIndex);
Array.Copy(array, ret, removeIndex);
Array.Copy(
array,
removeIndex + 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Common/tests/Tests/System/StringTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7288,7 +7288,7 @@ private static IEnumerable<T[]> Permute<T>(T[] input)
for (int i = 0; i < input.Length; i++)
{
var remainder = new T[input.Length - 1];
Array.Copy(input, 0, remainder, 0, i);
Array.Copy(input, remainder, i);
Array.Copy(input, i + 1, remainder, i, input.Length - i - 1);
foreach (T[] output in Permute(remainder))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static RuntimeBinderException Error(ErrorCode id, params ErrArg[] args)
{
// Copy the strings over to another buffer.
string[] prgpszNew = new string[cpsz];
Array.Copy(prgpsz, 0, prgpszNew, 0, cpsz);
Array.Copy(prgpsz, prgpszNew, cpsz);

for (int i = 0; i < cpsz; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public static TypeArray Concat(TypeArray pta1, TypeArray pta2)
}

CType[] combined = new CType[prgtype1.Length + prgtype2.Length];
Array.Copy(prgtype1, 0, combined, 0, prgtype1.Length);
Array.Copy(prgtype1, combined, prgtype1.Length);
Array.Copy(prgtype2, 0, combined, prgtype1.Length, prgtype2.Length);
return Allocate(combined);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public static TypeArray SubstTypeArray(TypeArray taSrc, SubstContext ctx)
if (src != dst)
{
CType[] dsts = new CType[srcs.Length];
Array.Copy(srcs, 0, dsts, 0, i);
Array.Copy(srcs, dsts, i);
dsts[i] = dst;
while (++i < srcs.Length)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ internal void LocalPush(T item, ref long emptyToNonEmptyListTransitionCount)
int headIdx = head & _mask;
if (headIdx == 0)
{
Array.Copy(_array, 0, newArray, 0, _array.Length);
Array.Copy(_array, newArray, _array.Length);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1837,7 +1837,7 @@ private void GrowTable(Tables tables)
if (_growLockArray && tables._locks.Length < MaxLockNumber)
{
newLocks = new object[tables._locks.Length * 2];
Array.Copy(tables._locks, 0, newLocks, 0, tables._locks.Length);
Array.Copy(tables._locks, newLocks, tables._locks.Length);
for (int i = tables._locks.Length; i < newLocks.Length; i++)
{
newLocks[i] = new object();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ internal static ImmutableArray<T> CreateDefensiveCopy<T>(T[] items)

// defensive copy
var tmp = new T[items.Length];
Array.Copy(items, 0, tmp, 0, items.Length);
Array.Copy(items, tmp, items.Length);
return new ImmutableArray<T>(tmp);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public int Capacity
var temp = new T[value];
if (_count > 0)
{
Array.Copy(_elements, 0, temp, 0, _count);
Array.Copy(_elements, temp, _count);
}

_elements = temp;
Expand Down Expand Up @@ -437,7 +437,7 @@ public T[] ToArray()
}

T[] result = new T[this.Count];
Array.Copy(_elements, 0, result, 0, this.Count);
Array.Copy(_elements, result, this.Count);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public ImmutableArray<T> Insert(int index, T item)

if (index != 0)
{
Array.Copy(self.array, 0, tmp, 0, index);
Array.Copy(self.array, tmp, index);
}
if (index != self.Length)
{
Expand Down Expand Up @@ -355,7 +355,7 @@ public ImmutableArray<T> InsertRange(int index, IEnumerable<T> items)

if (index != 0)
{
Array.Copy(self.array, 0, tmp, 0, index);
Array.Copy(self.array, tmp, index);
}
if (index != self.Length)
{
Expand Down Expand Up @@ -407,7 +407,7 @@ public ImmutableArray<T> InsertRange(int index, ImmutableArray<T> items)

if (index != 0)
{
Array.Copy(self.array, 0, tmp, 0, index);
Array.Copy(self.array, tmp, index);
}
if (index != self.Length)
{
Expand Down Expand Up @@ -474,7 +474,7 @@ public ImmutableArray<T> SetItem(int index, T item)
Requires.Range(index >= 0 && index < self.Length, nameof(index));

T[] tmp = new T[self.Length];
Array.Copy(self.array, 0, tmp, 0, self.Length);
Array.Copy(self.array, tmp, self.Length);
tmp[index] = item;
return new ImmutableArray<T>(tmp);
}
Expand Down Expand Up @@ -580,7 +580,7 @@ public ImmutableArray<T> RemoveRange(int index, int length)
}

T[] tmp = new T[self.Length - length];
Array.Copy(self.array, 0, tmp, 0, index);
Array.Copy(self.array, tmp, index);
Array.Copy(self.array, index + length, tmp, index, self.Length - index - length);
return new ImmutableArray<T>(tmp);
}
Expand Down Expand Up @@ -800,7 +800,7 @@ public ImmutableArray<T> Sort(int index, int count, IComparer<T> comparer)
if (outOfOrder)
{
var tmp = new T[self.Length];
Array.Copy(self.array, 0, tmp, 0, self.Length);
Array.Copy(self.array, tmp, self.Length);
Array.Sort(tmp, index, count, comparer);
return new ImmutableArray<T>(tmp);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ public virtual int Capacity
object[] newValues = new object[value];
if (_size > 0)
{
Array.Copy(keys, 0, newKeys, 0, _size);
Array.Copy(values, 0, newValues, 0, _size);
Array.Copy(keys, newKeys, _size);
Array.Copy(values, newValues, _size);
}
keys = newKeys;
values = newValues;
Expand Down Expand Up @@ -301,8 +301,8 @@ public virtual void Clear()
public virtual object Clone()
{
SortedList sl = new SortedList(_size);
Array.Copy(keys, 0, sl.keys, 0, _size);
Array.Copy(values, 0, sl.values, 0, _size);
Array.Copy(keys, sl.keys, _size);
Array.Copy(values, sl.values, _size);
sl._size = _size;
sl.version = version;
sl.comparer = comparer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public virtual object Clone()
{
Stack s = new Stack(_size);
s._size = _size;
Array.Copy(_array, 0, s._array, 0, _size);
Array.Copy(_array, s._array, _size);
s._version = _version;
return s;
}
Expand Down Expand Up @@ -183,7 +183,7 @@ public virtual void Push(object? obj)
if (_size == _array.Length)
{
object[] newArray = new object[2 * _array.Length];
Array.Copy(_array, 0, newArray, 0, _size);
Array.Copy(_array, newArray, _size);
_array = newArray;
}
_array[_size++] = obj;
Expand Down
4 changes: 2 additions & 2 deletions src/System.Collections/src/System/Collections/BitArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public BitArray(int[] values)
}

m_array = new int[values.Length];
Array.Copy(values, 0, m_array, 0, values.Length);
Array.Copy(values, m_array, values.Length);
m_length = values.Length * BitsPerInt32;

_version = 0;
Expand All @@ -181,7 +181,7 @@ public BitArray(BitArray bits)

Debug.Assert(bits.m_array.Length <= arrayLength);

Array.Copy(bits.m_array, 0, m_array, 0, arrayLength);
Array.Copy(bits.m_array, m_array, arrayLength);
m_length = bits.m_length;

_version = bits._version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ private void SetCapacity(int newSize)
Slot[] newSlots = new Slot[newSize];
if (_slots != null)
{
Array.Copy(_slots, 0, newSlots, 0, _lastIndex);
Array.Copy(_slots, newSlots, _lastIndex);
}

int[] newBuckets = new int[newSize];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ public int Capacity
TValue[] newValues = new TValue[value];
if (_size > 0)
{
Array.Copy(keys, 0, newKeys, 0, _size);
Array.Copy(values, 0, newValues, 0, _size);
Array.Copy(keys, newKeys, _size);
Array.Copy(values, newValues, _size);
}
keys = newKeys;
values = newValues;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void AddAfter_LLNode()
linkedList.AddFirst(headItems[0]);

tempItems = new T[headItems.Length];
Array.Copy(headItems, 0, tempItems, 0, headItems.Length);
Array.Copy(headItems, tempItems, headItems.Length);
Array.Reverse(tempItems, 1, headItems.Length - 1);

for (int i = 1; i < arraySize; ++i)
Expand All @@ -66,7 +66,7 @@ public void AddAfter_LLNode()
linkedList.AddLast(headItems[1]);

tempItems = new T[headItems.Length];
Array.Copy(headItems, 0, tempItems, 0, headItems.Length);
Array.Copy(headItems, tempItems, headItems.Length);
Array.Reverse(tempItems, 2, headItems.Length - 2);

for (int i = 2; i < arraySize; ++i)
Expand Down Expand Up @@ -128,7 +128,7 @@ public void AddAfter_LLNode()
linkedList.AddAfter(linkedList.Last, tailItems[i]);

T[] tempItems2 = new T[tempItems.Length + tailItems.Length];
Array.Copy(tempItems, 0, tempItems2, 0, tempItems.Length);
Array.Copy(tempItems, tempItems2, tempItems.Length);
Array.Copy(tailItems, 0, tempItems2, tempItems.Length, tailItems.Length);

InitialItems_Tests(linkedList, tempItems2);
Expand Down Expand Up @@ -173,7 +173,7 @@ public void AddAfter_LLNode()
}

tempItems = new T[headItemsReverse.Length + tailItems.Length];
Array.Copy(headItemsReverse, 0, tempItems, 0, headItemsReverse.Length);
Array.Copy(headItemsReverse, tempItems, headItemsReverse.Length);
Array.Copy(tailItems, 0, tempItems, headItemsReverse.Length, tailItems.Length);
InitialItems_Tests(linkedList, tempItems);
}
Expand Down Expand Up @@ -247,7 +247,7 @@ public void AddAfter_LLNode_LLNode()
linkedList.AddFirst(headItems[0]);

tempItems = new T[headItems.Length];
Array.Copy(headItems, 0, tempItems, 0, headItems.Length);
Array.Copy(headItems, tempItems, headItems.Length);
Array.Reverse(tempItems, 1, headItems.Length - 1);

for (int i = 1; i < arraySize; ++i)
Expand All @@ -268,7 +268,7 @@ public void AddAfter_LLNode_LLNode()
linkedList.AddFirst(headItems[0]);
linkedList.AddLast(headItems[1]);
tempItems = new T[headItems.Length];
Array.Copy(headItems, 0, tempItems, 0, headItems.Length);
Array.Copy(headItems, tempItems, headItems.Length);
Array.Reverse(tempItems, 2, headItems.Length - 2);

for (int i = 2; i < arraySize; ++i)
Expand Down Expand Up @@ -331,7 +331,7 @@ public void AddAfter_LLNode_LLNode()
linkedList.AddAfter(linkedList.Last, new LinkedListNode<T>(tailItems[i]));

T[] tempItems2 = new T[tempItems.Length + tailItems.Length];
Array.Copy(tempItems, 0, tempItems2, 0, tempItems.Length);
Array.Copy(tempItems, tempItems2, tempItems.Length);
Array.Copy(tailItems, 0, tempItems2, tempItems.Length, tailItems.Length);

InitialItems_Tests(linkedList, tempItems2);
Expand Down Expand Up @@ -384,7 +384,7 @@ public void AddAfter_LLNode_LLNode()
}

tempItems = new T[headItemsReverse.Length + tailItems.Length];
Array.Copy(headItemsReverse, 0, tempItems, 0, headItemsReverse.Length);
Array.Copy(headItemsReverse, tempItems, headItemsReverse.Length);
Array.Copy(tailItems, 0, tempItems, headItemsReverse.Length, tailItems.Length);
InitialItems_Tests(linkedList, tempItems);
}
Expand Down
Loading