Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit c3bf2d7

Browse files
committed
Merge pull request #1998 from stephentoub/array_removal
Remove usage of ArrayT<T>
2 parents 8d8d3bc + 54ec4d0 commit c3bf2d7

File tree

21 files changed

+48
-84
lines changed

21 files changed

+48
-84
lines changed

src/Common/src/System/Collections/Generic/EnumerableHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ internal static T[] ToArray<T>(IEnumerable<T> source, out int length)
7272
newLength = count + 1;
7373
}
7474

75-
arr = ArrayT<T>.Resize(arr, newLength, count);
75+
Array.Resize(ref arr, newLength);
7676
}
7777
arr[count++] = item;
7878
}

src/Common/src/System/Collections/Generic/LowLevelList.cs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,9 @@ public int Capacity
137137
{
138138
if (value > 0)
139139
{
140-
#if TYPE_LOADER_IMPLEMENTATION
141140
T[] newItems = new T[value];
142-
for (int i = 0; i < _size; i++)
143-
newItems[i] = _items[i];
141+
Array.Copy(_items, 0, newItems, 0, _size);
144142
_items = newItems;
145-
#else
146-
_items = ArrayT<T>.Resize(_items, value, _size);
147-
#endif
148143
}
149144
else
150145
{
@@ -237,7 +232,7 @@ public void Clear()
237232
{
238233
if (_size > 0)
239234
{
240-
ArrayT<T>.Clear(_items, 0, _size); // Don't need to doc this but we clear the elements so that the gc can reclaim the references.
235+
Array.Clear(_items, 0, _size); // Don't need to doc this but we clear the elements so that the gc can reclaim the references.
241236
_size = 0;
242237
}
243238
_version++;
@@ -279,13 +274,13 @@ public void CopyTo(int index, T[] array, int arrayIndex, int count)
279274
Contract.EndContractBlock();
280275

281276
// Delegate rest of error checking to Array.Copy.
282-
ArrayT<T>.Copy(_items, index, array, arrayIndex, count);
277+
Array.Copy(_items, index, array, arrayIndex, count);
283278
}
284279

285280
public void CopyTo(T[] array, int arrayIndex)
286281
{
287282
// Delegate rest of error checking to Array.Copy.
288-
ArrayT<T>.Copy(_items, 0, array, arrayIndex, _size);
283+
Array.Copy(_items, 0, array, arrayIndex, _size);
289284
}
290285

291286
// Returns the index of the first occurrence of a given value in a range of
@@ -338,7 +333,7 @@ public void Insert(int index, T item)
338333
if (_size == _items.Length) EnsureCapacity(_size + 1);
339334
if (index < _size)
340335
{
341-
ArrayT<T>.Copy(_items, index, _items, index + 1, _size - index);
336+
Array.Copy(_items, index, _items, index + 1, _size - index);
342337
}
343338
_items[index] = item;
344339
_size++;
@@ -372,22 +367,22 @@ public void InsertRange(int index, IEnumerable<T> collection)
372367
EnsureCapacity(_size + count);
373368
if (index < _size)
374369
{
375-
ArrayT<T>.Copy(_items, index, _items, index + count, _size - index);
370+
Array.Copy(_items, index, _items, index + count, _size - index);
376371
}
377372

378373
// If we're inserting a List into itself, we want to be able to deal with that.
379374
if (this == c)
380375
{
381376
// Copy first part of _items to insert location
382-
ArrayT<T>.Copy(_items, 0, _items, index, index);
377+
Array.Copy(_items, 0, _items, index, index);
383378
// Copy last part of _items back to inserted location
384-
ArrayT<T>.Copy(_items, index + count, _items, index * 2, _size - index);
379+
Array.Copy(_items, index + count, _items, index * 2, _size - index);
385380
}
386381
else
387382
{
388383
T[] itemsToInsert = new T[count];
389384
c.CopyTo(itemsToInsert, 0);
390-
ArrayT<T>.Copy(itemsToInsert, 0, _items, index, count);
385+
Array.Copy(itemsToInsert, 0, _items, index, count);
391386
}
392387
_size += count;
393388
}
@@ -451,7 +446,7 @@ public int RemoveAll(Predicate<T> match)
451446
}
452447
}
453448

454-
ArrayT<T>.Clear(_items, freeIndex, _size - freeIndex);
449+
Array.Clear(_items, freeIndex, _size - freeIndex);
455450
int result = _size - freeIndex;
456451
_size = freeIndex;
457452
_version++;
@@ -471,7 +466,7 @@ public void RemoveAt(int index)
471466
_size--;
472467
if (index < _size)
473468
{
474-
ArrayT<T>.Copy(_items, index + 1, _items, index, _size - index);
469+
Array.Copy(_items, index + 1, _items, index, _size - index);
475470
}
476471
_items[_size] = default(T);
477472
_version++;
@@ -485,7 +480,7 @@ public T[] ToArray()
485480
Contract.Ensures(Contract.Result<T[]>().Length == Count);
486481

487482
T[] array = new T[_size];
488-
ArrayT<T>.Copy(_items, 0, array, 0, _size);
483+
Array.Copy(_items, 0, array, 0, _size);
489484
return array;
490485
}
491486
#endif

src/System.Collections.Concurrent/src/System.Collections.Concurrent.csproj

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@
2929
<Compile Include="System\Collections\Concurrent\PartitionerStatic.cs" />
3030
<Compile Include="System\Collections\Concurrent\PlatformHelper.cs" />
3131
</ItemGroup>
32-
<ItemGroup>
33-
<Compile Include="$(CommonPath)\System\ArrayT.cs">
34-
<Link>Common\System\ArrayT.cs</Link>
35-
</Compile>
36-
</ItemGroup>
3732
<ItemGroup>
3833
<None Include="project.json" />
3934
</ItemGroup>

src/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentDictionary.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,8 @@ private void GrowTable(Tables tables)
16851685
// Add more locks
16861686
if (_growLockArray && tables._locks.Length < MAX_LOCK_NUMBER)
16871687
{
1688-
newLocks = ArrayT<object>.Resize(tables._locks, tables._locks.Length * 2, tables._locks.Length);
1688+
newLocks = new object[tables._locks.Length * 2];
1689+
Array.Copy(tables._locks, 0, newLocks, 0, tables._locks.Length);
16891690
for (int i = tables._locks.Length; i < newLocks.Length; i++)
16901691
{
16911692
newLocks[i] = new object();

src/System.Collections.Concurrent/src/System/Collections/Concurrent/PartitionerStatic.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ private void TryCopyFromFillBuffer(KeyValuePair<long, TSource>[] destArray,
665665
{
666666
// adjust index and do the actual copy
667667
actualNumElementsGrabbed = (endPos < _fillBufferSize) ? endPos : _fillBufferSize - beginPos;
668-
ArrayT<KeyValuePair<long, TSource>>.Copy(fillBufferLocalRef, beginPos, destArray, 0, actualNumElementsGrabbed);
668+
Array.Copy(fillBufferLocalRef, beginPos, destArray, 0, actualNumElementsGrabbed);
669669
}
670670

671671
// let the record show we are no longer accessing the buffer

src/System.Collections/src/System.Collections.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@
4242
<Compile Include="System\Collections\StructuralComparisons.cs" />
4343
</ItemGroup>
4444
<ItemGroup>
45-
<Compile Include="$(CommonPath)\System\ArrayT.cs">
46-
<Link>Common\System\ArrayT.cs</Link>
47-
</Compile>
4845
<Compile Include="$(CommonPath)\System\Collections\HashHelpers.cs">
4946
<Link>Common\System\Collections\HashHelpers.cs</Link>
5047
</Compile>

src/System.Collections/src/System/Collections/Generic/HashSet.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ public void Clear()
157157

158158
// clear the elements so that the gc can reclaim the references.
159159
// clear only up to _lastIndex for _slots
160-
ArrayT<Slot>.Clear(_slots, 0, _lastIndex);
161-
ArrayT<int>.Clear(_buckets, 0, _buckets.Length);
160+
Array.Clear(_slots, 0, _lastIndex);
161+
Array.Clear(_buckets, 0, _buckets.Length);
162162
_lastIndex = 0;
163163
_count = 0;
164164
_freeList = -1;
@@ -919,11 +919,11 @@ private void SetCapacity(int newSize, bool forceNewHashCodes)
919919

920920
Debug.Assert(_buckets != null, "SetCapacity called on a set with no elements");
921921

922-
Slot[] newSlots;
923-
if (_slots == null)
924-
newSlots = new Slot[newSize];
925-
else
926-
newSlots = ArrayT<Slot>.Resize(_slots, newSize, _lastIndex);
922+
Slot[] newSlots = new Slot[newSize];
923+
if (_slots != null)
924+
{
925+
Array.Copy(_slots, 0, newSlots, 0, _lastIndex);
926+
}
927927

928928
if (forceNewHashCodes)
929929
{

src/System.Collections/src/System/Collections/Generic/Queue.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ Object System.Collections.ICollection.SyncRoot
102102
public void Clear()
103103
{
104104
if (_head < _tail)
105-
ArrayT<T>.Clear(_array, _head, _size);
105+
Array.Clear(_array, _head, _size);
106106
else
107107
{
108-
ArrayT<T>.Clear(_array, _head, _array.Length - _head);
109-
ArrayT<T>.Clear(_array, 0, _tail);
108+
Array.Clear(_array, _head, _array.Length - _head);
109+
Array.Clear(_array, 0, _tail);
110110
}
111111

112112
_head = 0;
@@ -141,11 +141,11 @@ public void CopyTo(T[] array, int arrayIndex)
141141
if (numToCopy == 0) return;
142142

143143
int firstPart = (_array.Length - _head < numToCopy) ? _array.Length - _head : numToCopy;
144-
ArrayT<T>.Copy(_array, _head, array, arrayIndex, firstPart);
144+
Array.Copy(_array, _head, array, arrayIndex, firstPart);
145145
numToCopy -= firstPart;
146146
if (numToCopy > 0)
147147
{
148-
ArrayT<T>.Copy(_array, 0, array, arrayIndex + _array.Length - _head, numToCopy);
148+
Array.Copy(_array, 0, array, arrayIndex + _array.Length - _head, numToCopy);
149149
}
150150
}
151151

@@ -313,12 +313,12 @@ public T[] ToArray()
313313

314314
if (_head < _tail)
315315
{
316-
ArrayT<T>.Copy(_array, _head, arr, 0, _size);
316+
Array.Copy(_array, _head, arr, 0, _size);
317317
}
318318
else
319319
{
320-
ArrayT<T>.Copy(_array, _head, arr, 0, _array.Length - _head);
321-
ArrayT<T>.Copy(_array, 0, arr, _array.Length - _head, _tail);
320+
Array.Copy(_array, _head, arr, 0, _array.Length - _head);
321+
Array.Copy(_array, 0, arr, _array.Length - _head, _tail);
322322
}
323323

324324
return arr;
@@ -334,12 +334,12 @@ private void SetCapacity(int capacity)
334334
{
335335
if (_head < _tail)
336336
{
337-
ArrayT<T>.Copy(_array, _head, newarray, 0, _size);
337+
Array.Copy(_array, _head, newarray, 0, _size);
338338
}
339339
else
340340
{
341-
ArrayT<T>.Copy(_array, _head, newarray, 0, _array.Length - _head);
342-
ArrayT<T>.Copy(_array, 0, newarray, _array.Length - _head, _tail);
341+
Array.Copy(_array, _head, newarray, 0, _array.Length - _head);
342+
Array.Copy(_array, 0, newarray, _array.Length - _head, _tail);
343343
}
344344
}
345345

src/System.Collections/src/System/Collections/Generic/Stack.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Object System.Collections.ICollection.SyncRoot
8686
/// <include file='doc\Stack.uex' path='docs/doc[@for="Stack.Clear"]/*' />
8787
public void Clear()
8888
{
89-
ArrayT<T>.Clear(_array, 0, _size); // Don't need to doc this but we clear the elements so that the gc can reclaim the references.
89+
Array.Clear(_array, 0, _size); // Don't need to doc this but we clear the elements so that the gc can reclaim the references.
9090
_size = 0;
9191
_version++;
9292
}
@@ -141,7 +141,7 @@ public void CopyTo(T[] array, int arrayIndex)
141141
else
142142
{
143143
// Legacy fallback in case we ever end up copying within the same array.
144-
ArrayT<T>.Copy(_array, 0, array, arrayIndex, _size);
144+
Array.Copy(_array, 0, array, arrayIndex, _size);
145145
Array.Reverse(array, arrayIndex, _size);
146146
}
147147
}
@@ -208,8 +208,7 @@ public void TrimExcess()
208208
int threshold = (int)(((double)_array.Length) * 0.9);
209209
if (_size < threshold)
210210
{
211-
T[] newarray = ArrayT<T>.Resize(_array, _size, _size);
212-
_array = newarray;
211+
Array.Resize(ref _array, _size);
213212
_version++;
214213
}
215214
}
@@ -244,8 +243,7 @@ public void Push(T item)
244243
{
245244
if (_size == _array.Length)
246245
{
247-
T[] newArray = ArrayT<T>.Resize(_array, (_array.Length == 0) ? DefaultCapacity : 2 * _array.Length, _size);
248-
_array = newArray;
246+
Array.Resize(ref _array, (_array.Length == 0) ? DefaultCapacity : 2 * _array.Length);
249247
}
250248
_array[_size++] = item;
251249
_version++;

src/System.Linq.Parallel/src/System.Linq.Parallel.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,6 @@
158158
</ItemGroup>
159159
<!-- Common or Common-branched source files -->
160160
<ItemGroup>
161-
<Compile Include="$(CommonPath)\System\ArrayT.cs">
162-
<Link>Common\System\ArrayT.cs</Link>
163-
</Compile>
164161
</ItemGroup>
165162
<!-- Resource files -->
166163
<ItemGroup>

0 commit comments

Comments
 (0)