Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.

Commit e32a6b8

Browse files
committed
Use simple Array.Copy overload where possible (dotnet/coreclr#27641)
The simple Array.Copy overload does not come with a performance penalty anymore. Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
1 parent cd978fb commit e32a6b8

File tree

14 files changed

+31
-31
lines changed

14 files changed

+31
-31
lines changed

src/System.Private.CoreLib/shared/System/Collections/ArrayList.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public virtual int Capacity
106106
object[] newItems = new object[value];
107107
if (_size > 0)
108108
{
109-
Array.Copy(_items, 0, newItems, 0, _size);
109+
Array.Copy(_items, newItems, _size);
110110
}
111111
_items = newItems;
112112
}
@@ -248,7 +248,7 @@ public virtual object Clone()
248248
ArrayList la = new ArrayList(_size);
249249
la._size = _size;
250250
la._version = _version;
251-
Array.Copy(_items, 0, la._items, 0, _size);
251+
Array.Copy(_items, la._items, _size);
252252
return la;
253253
}
254254

@@ -714,7 +714,7 @@ public static ArrayList Synchronized(ArrayList list)
714714
return Array.Empty<object>();
715715

716716
object?[] array = new object[_size];
717-
Array.Copy(_items, 0, array, 0, _size);
717+
Array.Copy(_items, array, _size);
718718
return array;
719719
}
720720

@@ -729,7 +729,7 @@ public virtual Array ToArray(Type type)
729729
throw new ArgumentNullException(nameof(type));
730730

731731
Array array = Array.CreateInstance(type, _size);
732-
Array.Copy(_items, 0, array, 0, _size);
732+
Array.Copy(_items, array, _size);
733733
return array;
734734
}
735735

src/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ private void Resize(int newSize, bool forceNewHashCodes)
727727
Entry[] entries = new Entry[newSize];
728728

729729
int count = _count;
730-
Array.Copy(_entries, 0, entries, 0, count);
730+
Array.Copy(_entries, entries, count);
731731

732732
if (default(TKey)! == null && forceNewHashCodes) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
733733
{

src/System.Private.CoreLib/shared/System/Collections/Generic/List.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public int Capacity
113113
T[] newItems = new T[value];
114114
if (_size > 0)
115115
{
116-
Array.Copy(_items, 0, newItems, 0, _size);
116+
Array.Copy(_items, newItems, _size);
117117
}
118118
_items = newItems;
119119
}
@@ -1035,7 +1035,7 @@ public T[] ToArray()
10351035
}
10361036

10371037
T[] array = new T[_size];
1038-
Array.Copy(_items, 0, array, 0, _size);
1038+
Array.Copy(_items, array, _size);
10391039
return array;
10401040
}
10411041

src/System.Private.CoreLib/shared/System/DefaultBinder.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public sealed override MethodBase BindToMethod(
304304
{
305305
object[] objs = new object[parms.Length];
306306
int lastPos = parms.Length - 1;
307-
Array.Copy(args, 0, objs, 0, lastPos);
307+
Array.Copy(args, objs, lastPos);
308308
objs[lastPos] = Array.CreateInstance(paramArrayTypes[0], 1);
309309
((Array)objs[lastPos]).SetValue(args[lastPos], 0);
310310
args = objs;
@@ -334,7 +334,7 @@ public sealed override MethodBase BindToMethod(
334334
{
335335
object[] objs = new object[parms.Length];
336336
int paramArrayPos = parms.Length - 1;
337-
Array.Copy(args, 0, objs, 0, paramArrayPos);
337+
Array.Copy(args, objs, paramArrayPos);
338338
objs[paramArrayPos] = Array.CreateInstance(paramArrayTypes[0], args.Length - paramArrayPos);
339339
Array.Copy(args, paramArrayPos, (System.Array)objs[paramArrayPos], 0, args.Length - paramArrayPos);
340340
args = objs;
@@ -384,7 +384,7 @@ public sealed override MethodBase BindToMethod(
384384
{
385385
object[] objs = new object[parameters.Length];
386386
int lastPos = parameters.Length - 1;
387-
Array.Copy(args, 0, objs, 0, lastPos);
387+
Array.Copy(args, objs, lastPos);
388388
objs[lastPos] = Array.CreateInstance(paramArrayTypes[currentMin], 1);
389389
((Array)objs[lastPos]).SetValue(args[lastPos], 0);
390390
args = objs;
@@ -417,7 +417,7 @@ public sealed override MethodBase BindToMethod(
417417
{
418418
object[] objs = new object[parameters.Length];
419419
int paramArrayPos = parameters.Length - 1;
420-
Array.Copy(args, 0, objs, 0, paramArrayPos);
420+
Array.Copy(args, objs, paramArrayPos);
421421
objs[paramArrayPos] = Array.CreateInstance(paramArrayTypes[currentMin], args.Length - paramArrayPos);
422422
Array.Copy(args, paramArrayPos, (System.Array)objs[paramArrayPos], 0, args.Length - paramArrayPos);
423423
args = objs;
@@ -750,7 +750,7 @@ public sealed override void ReorderArgumentArray(ref object?[] args, object stat
750750
{
751751
// must be args.Length < state.originalSize
752752
object[] newArgs = new object[args.Length];
753-
Array.Copy(args, 0, newArgs, 0, paramArrayPos);
753+
Array.Copy(args, newArgs, paramArrayPos);
754754
for (int i = paramArrayPos, j = 0; i < newArgs.Length; i++, j++)
755755
{
756756
newArgs[i] = ((object[])args[paramArrayPos]!)[j];
@@ -763,7 +763,7 @@ public sealed override void ReorderArgumentArray(ref object?[] args, object stat
763763
if (args.Length > binderState._originalSize)
764764
{
765765
object[] newArgs = new object[binderState._originalSize];
766-
Array.Copy(args, 0, newArgs, 0, binderState._originalSize);
766+
Array.Copy(args, newArgs, binderState._originalSize);
767767
args = newArgs;
768768
}
769769
}

src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/CounterGroup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private static void EnsureEventSourceIndexAvailable(int eventSourceIndex)
8989
else if (eventSourceIndex >= CounterGroup.s_counterGroups.Length)
9090
{
9191
WeakReference<CounterGroup>[] newCounterGroups = new WeakReference<CounterGroup>[eventSourceIndex + 1];
92-
Array.Copy(CounterGroup.s_counterGroups, 0, newCounterGroups, 0, CounterGroup.s_counterGroups.Length);
92+
Array.Copy(CounterGroup.s_counterGroups, newCounterGroups, CounterGroup.s_counterGroups.Length);
9393
CounterGroup.s_counterGroups = newCounterGroups;
9494
}
9595
}

src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3502,7 +3502,7 @@ private static void AddEventDescriptor(
35023502
if (eventData.Length <= eventAttribute.EventId)
35033503
{
35043504
EventMetadata[] newValues = new EventMetadata[Math.Max(eventData.Length + 16, eventAttribute.EventId + 1)];
3505-
Array.Copy(eventData, 0, newValues, 0, eventData.Length);
3505+
Array.Copy(eventData, newValues, eventData.Length);
35063506
eventData = newValues;
35073507
}
35083508

@@ -3542,7 +3542,7 @@ private static void TrimEventDescriptors(ref EventMetadata[] eventData)
35423542
if (eventData.Length - idx > 2) // allow one wasted slot.
35433543
{
35443544
EventMetadata[] newValues = new EventMetadata[idx + 1];
3545-
Array.Copy(eventData, 0, newValues, 0, newValues.Length);
3545+
Array.Copy(eventData, newValues, newValues.Length);
35463546
eventData = newValues;
35473547
}
35483548
}

src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/TraceLogging/ConcurrentSet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public ItemType GetOrAdd(ItemType newItem)
107107

108108
int oldLength = oldItems.Length;
109109
newItems = new ItemType[oldLength + 1];
110-
Array.Copy(oldItems, 0, newItems, 0, lo);
110+
Array.Copy(oldItems, newItems, lo);
111111
newItems[lo] = newItem;
112112
Array.Copy(oldItems, lo, newItems, lo + 1, oldLength - lo);
113113
}

src/System.Private.CoreLib/shared/System/Globalization/CultureData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ internal CalendarId[] CalendarIds
15671567

15681568
// It worked, remember the list
15691569
CalendarId[] temp = new CalendarId[count];
1570-
Array.Copy(calendars, 0, temp, 0, count);
1570+
Array.Copy(calendars, temp, count);
15711571

15721572
// Want 1st calendar to be default
15731573
// Prior to Vista the enumeration didn't have default calendar first

src/System.Private.CoreLib/shared/System/Globalization/StringInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public static int[] ParseCombiningCharacters(string str)
287287
if (resultCount < len)
288288
{
289289
int[] returnArray = new int[resultCount];
290-
Array.Copy(result, 0, returnArray, 0, resultCount);
290+
Array.Copy(result, returnArray, resultCount);
291291
return returnArray;
292292
}
293293
return result;

src/System.Private.CoreLib/shared/System/Runtime/Serialization/SerializationInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ private void ExpandArrays()
264264
object[] newData = new object[newSize];
265265
Type[] newTypes = new Type[newSize];
266266

267-
Array.Copy(_names, 0, newMembers, 0, _count);
268-
Array.Copy(_values, 0, newData, 0, _count);
269-
Array.Copy(_types, 0, newTypes, 0, _count);
267+
Array.Copy(_names, newMembers, _count);
268+
Array.Copy(_values, newData, _count);
269+
Array.Copy(_types, newTypes, _count);
270270

271271
// Assign the new arrays back to the member vars.
272272
_names = newMembers;

0 commit comments

Comments
 (0)