Skip to content

Commit bee08b6

Browse files
authored
Merge pull request #970 from Unity-Technologies/unity-master-list-add-range-avoid-allocation
Avoid temporary allocation in List.AddRange (case 1041305)
2 parents 1625551 + 64c364e commit bee08b6

File tree

1 file changed

+4
-0
lines changed
  • mcs/class/referencesource/mscorlib/system/collections/generic

1 file changed

+4
-0
lines changed

mcs/class/referencesource/mscorlib/system/collections/generic/list.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,9 +732,13 @@ public void InsertRange(int index, IEnumerable<T> collection) {
732732
Array.Copy(_items, index+count, _items, index*2, _size-index);
733733
}
734734
else {
735+
#if MONO
736+
c.CopyTo(_items, index);
737+
#else
735738
T[] itemsToInsert = new T[count];
736739
c.CopyTo(itemsToInsert, 0);
737740
itemsToInsert.CopyTo(_items, index);
741+
#endif
738742
}
739743
_size += count;
740744
}

0 commit comments

Comments
 (0)