зеркало из https://github.com/App-vNext/corefx.git
Added guards to ICollection.CopyTo implementations to avoid allocating the indices array for SetValue when the collection being copied from is empty
This commit is contained in:
Родитель
d1d7001376
Коммит
31e929ce15
|
@ -345,6 +345,11 @@ namespace System.Collections.Immutable
|
|||
Requires.Range(arrayIndex >= 0, "arrayIndex");
|
||||
Requires.Range(array.Length >= arrayIndex + this.Count, "arrayIndex");
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int[] indices = new int[1]; // SetValue takes a params array; lifting out the implicit allocation from the loop
|
||||
foreach (var item in this)
|
||||
{
|
||||
|
|
|
@ -780,6 +780,11 @@ namespace System.Collections.Immutable
|
|||
Requires.Range(arrayIndex >= 0, "arrayIndex");
|
||||
Requires.Range(array.Length >= arrayIndex + this.Count, "arrayIndex");
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int[] indices = new int[1]; // SetValue takes a params array; lifting out the implicit allocation from the loop
|
||||
foreach (var item in this)
|
||||
{
|
||||
|
|
|
@ -562,6 +562,11 @@ namespace System.Collections.Immutable
|
|||
Requires.Range(arrayIndex >= 0, "arrayIndex");
|
||||
Requires.Range(array.Length >= arrayIndex + this.Count, "arrayIndex");
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int[] indices = new int[1]; // SetValue takes a params array; lifting out the implicit allocation from the loop
|
||||
foreach (T item in this)
|
||||
{
|
||||
|
|
|
@ -2590,6 +2590,11 @@ namespace System.Collections.Immutable
|
|||
Requires.Range(arrayIndex >= 0, "arrayIndex");
|
||||
Requires.Range(array.Length >= arrayIndex + this.Count, "arrayIndex");
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int[] indices = new int[1]; // SetValue takes a params array; lifting out the implicit allocation from the loop
|
||||
foreach (var element in this)
|
||||
{
|
||||
|
|
|
@ -1381,6 +1381,11 @@ namespace System.Collections.Immutable
|
|||
Requires.Range(arrayIndex >= 0, "arrayIndex");
|
||||
Requires.Range(array.Length >= arrayIndex + dictionarySize, "arrayIndex");
|
||||
|
||||
if (IsEmpty)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int[] indices = new int[1]; // SetValue takes a params array; lifting out the implicit allocation from the loop
|
||||
foreach (var item in this)
|
||||
{
|
||||
|
|
|
@ -1689,6 +1689,11 @@ namespace System.Collections.Immutable
|
|||
Requires.Range(arrayIndex >= 0, "arrayIndex");
|
||||
Requires.Range(array.Length >= arrayIndex + this.Count, "arrayIndex");
|
||||
|
||||
if (IsEmpty)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int[] indices = new int[1]; // SetValue takes a params array; lifting out the implicit allocation from the loop
|
||||
foreach (var item in this)
|
||||
{
|
||||
|
|
|
@ -139,6 +139,11 @@ namespace System.Collections.Immutable
|
|||
Requires.Range(arrayIndex >= 0, "arrayIndex");
|
||||
Requires.Range(array.Length >= arrayIndex + this.Count, "arrayIndex");
|
||||
|
||||
if (Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int[] indices = new int[1]; // SetValue takes a params array; lifting out the implicit allocation from the loop
|
||||
foreach (T item in this)
|
||||
{
|
||||
|
|
|
@ -246,6 +246,11 @@ namespace System.Xml
|
|||
|
||||
void ICollection.CopyTo(Array array, int index)
|
||||
{
|
||||
if (Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int[] indices = new int[1]; // SetValue takes a params array; lifting out the implicit allocation from the loop
|
||||
for (int i = 0, max = Count; i < max; i++, index++)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче