Skip to content

Commit f6239ca

Browse files
authored
Simplify Array.Copy(a, 0, b, 0, c) to Array.Copy(a, b, c) (dotnet/corefx#42343)
VS regex search and replace from `Array.Copy\((.+), 0, (.+), 0` to `Array.Copy($1, $2`, then manually reviewed. The only changes I reverted were those to the tests for Array itself. Commit migrated from dotnet/corefx@5ac93ba
1 parent 2dcbe73 commit f6239ca

183 files changed

Lines changed: 277 additions & 277 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/libraries/Common/src/Interop/Windows/BCrypt/BCryptAlgorithmCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static SafeBCryptAlgorithmHandle GetCachedBCryptAlgorithmHandle(string ha
4040

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

4646
// 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

src/libraries/Common/src/System/Collections/Generic/ArrayBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public T[] ToArray()
112112
// Avoid a bit of overhead (method call, some branches, extra codegen)
113113
// which would be incurred by using Array.Resize
114114
result = new T[_count];
115-
Array.Copy(_array, 0, result, 0, _count);
115+
Array.Copy(_array, result, _count);
116116
}
117117

118118
#if DEBUG
@@ -156,7 +156,7 @@ private void EnsureCapacity(int minimum)
156156
T[] next = new T[nextCapacity];
157157
if (_count > 0)
158158
{
159-
Array.Copy(_array!, 0, next, 0, _count);
159+
Array.Copy(_array!, next, _count);
160160
}
161161
_array = next;
162162
}

src/libraries/Common/src/System/Collections/Generic/LargeArrayBuilder.SpeedOpt.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ private void AllocateBuffer()
308308
int nextCapacity = Math.Min(_count == 0 ? StartingCapacity : _count * 2, _maxCapacity);
309309

310310
_current = new T[nextCapacity];
311-
Array.Copy(_first, 0, _current, 0, _count);
311+
Array.Copy(_first, _current, _count);
312312
_first = _current;
313313
}
314314
else

src/libraries/Common/tests/StaticTestGenerator/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ void WriteArgumentListStatic(object[]? arguments, ParameterInfo[] parameters)
497497
else if (arguments.Length < parameters.Length)
498498
{
499499
var newArguments = new object[parameters.Length];
500-
Array.Copy(arguments, 0, newArguments, 0, arguments.Length);
500+
Array.Copy(arguments, newArguments, arguments.Length);
501501
for (int i = arguments.Length; i < parameters.Length; i++)
502502
{
503503
if (parameters[i].HasDefaultValue)

src/libraries/Common/tests/System/Collections/IListTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ public void AddWithNullValueInMiddle()
477477
items = new object[sizeWithNull];
478478
list.Add(null);
479479
items[sizeWithNull/2] = null;
480-
Array.Copy(tempItems, 0, items, 0, sizeWithNull/2);
480+
Array.Copy(tempItems, items, sizeWithNull/2);
481481
Array.Copy(
482482
tempItems,
483483
sizeWithNull/2,
@@ -567,7 +567,7 @@ public void AddDuplicateValue()
567567
list.AddRange(tempItems);
568568
list.AddRange(tempItems);
569569

570-
Array.Copy(tempItems, 0, items, 0, 16);
570+
Array.Copy(tempItems, items, 16);
571571
Array.Copy(tempItems, 0, items, 16, 16);
572572
}
573573
CollectionAssert.Equal(items, list);
@@ -1311,7 +1311,7 @@ public void InsertAndRemove()
13111311
{
13121312
object newObject = GenerateItem();
13131313
list.Insert(i, newObject);
1314-
Array.Copy(items, 0, tempItems, 0, i);
1314+
Array.Copy(items, tempItems, i);
13151315
tempItems[i] = newObject;
13161316
Array.Copy(items, i, tempItems, i + 1, items.Length - i);
13171317
CollectionAssert.Equal(tempItems, list);
@@ -1533,7 +1533,7 @@ public void RemoveNull()
15331533
IList list = GetList(null);
15341534
object[] tempItems = GenerateItems(16);
15351535
list.AddRange(tempItems);
1536-
Array.Copy(tempItems, 0, items, 0, 11);
1536+
Array.Copy(tempItems, items, 11);
15371537
Array.Copy(tempItems, 12, items, 11, 4);
15381538
list.Insert(8, null);
15391539
list.Remove(tempItems[11]);

src/libraries/Common/tests/System/Collections/Utils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static T[] Push<T>(this T[] array, params T[] arguments)
4040
public static T[] RemoveAt<T>(this T[] array, int removeIndex)
4141
{
4242
var ret = new T[array.Length - 1];
43-
Array.Copy(array, 0, ret, 0, removeIndex);
43+
Array.Copy(array, ret, removeIndex);
4444
Array.Copy(
4545
array,
4646
removeIndex + 1,

src/libraries/Common/tests/Tests/System/StringTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7288,7 +7288,7 @@ private static IEnumerable<T[]> Permute<T>(T[] input)
72887288
for (int i = 0; i < input.Length; i++)
72897289
{
72907290
var remainder = new T[input.Length - 1];
7291-
Array.Copy(input, 0, remainder, 0, i);
7291+
Array.Copy(input, remainder, i);
72927292
Array.Copy(input, i + 1, remainder, i, input.Length - i - 1);
72937293
foreach (T[] output in Permute(remainder))
72947294
{

src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Errors/ErrorHandling.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static RuntimeBinderException Error(ErrorCode id, params ErrArg[] args)
6161
{
6262
// Copy the strings over to another buffer.
6363
string[] prgpszNew = new string[cpsz];
64-
Array.Copy(prgpsz, 0, prgpszNew, 0, cpsz);
64+
Array.Copy(prgpsz, prgpszNew, cpsz);
6565

6666
for (int i = 0; i < cpsz; i++)
6767
{

src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Types/TypeArray.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public static TypeArray Concat(TypeArray pta1, TypeArray pta2)
156156
}
157157

158158
CType[] combined = new CType[prgtype1.Length + prgtype2.Length];
159-
Array.Copy(prgtype1, 0, combined, 0, prgtype1.Length);
159+
Array.Copy(prgtype1, combined, prgtype1.Length);
160160
Array.Copy(prgtype2, 0, combined, prgtype1.Length, prgtype2.Length);
161161
return Allocate(combined);
162162
}

src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Types/TypeManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public static TypeArray SubstTypeArray(TypeArray taSrc, SubstContext ctx)
211211
if (src != dst)
212212
{
213213
CType[] dsts = new CType[srcs.Length];
214-
Array.Copy(srcs, 0, dsts, 0, i);
214+
Array.Copy(srcs, dsts, i);
215215
dsts[i] = dst;
216216
while (++i < srcs.Length)
217217
{

0 commit comments

Comments
 (0)