Skip to content

Commit

Permalink
Fast path Array::Resize with small arrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
kumpera committed Mar 25, 2013
1 parent 694f00b commit 4189fe3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions mcs/class/corlib/System/Array.cs
Expand Up @@ -2808,8 +2808,14 @@ public static void Resize<T> (ref T [] array, int newSize)
return;

T [] a = new T [newSize];
if (length != 0)
FastCopy (arr, 0, a, 0, Math.Min (newSize, length));
int tocopy = Math.Min (newSize, length);

if (tocopy < 9) {
for (int i = 0; i < tocopy; ++i)
UnsafeStore (a, i, UnsafeLoad (arr, i));
} else {
FastCopy (arr, 0, a, 0, tocopy);
}
array = a;
}

Expand Down

0 comments on commit 4189fe3

Please sign in to comment.