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

Commit 63cc027

Browse files
mikednjkotas
authored andcommitted
Prefer using Array.Length as upper for loop limit (#2513)
Port of dotnet/coreclr#8923
1 parent 896ed6b commit 63cc027

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

src/System.Private.CoreLib/src/System/Delegate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ public virtual Delegate[] GetInvocationList()
630630
int invocationCount = (int)m_extraFunctionPointerOrData;
631631
del = new Delegate[invocationCount];
632632

633-
for (int i = 0; i < invocationCount; i++)
633+
for (int i = 0; i < del.Length; i++)
634634
del[i] = invocationList[i];
635635
}
636636
return del;

src/System.Private.CoreLib/src/System/Reflection/Assembly.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,18 @@ public virtual Type[] GetTypes()
3838
{
3939
Module[] m = GetModules(false);
4040

41-
int numModules = m.Length;
4241
int finalLength = 0;
43-
Type[][] moduleTypes = new Type[numModules][];
42+
Type[][] moduleTypes = new Type[m.Length][];
4443

45-
for (int i = 0; i < numModules; i++)
44+
for (int i = 0; i < moduleTypes.Length; i++)
4645
{
4746
moduleTypes[i] = m[i].GetTypes();
4847
finalLength += moduleTypes[i].Length;
4948
}
5049

5150
int current = 0;
5251
Type[] ret = new Type[finalLength];
53-
for (int i = 0; i < numModules; i++)
52+
for (int i = 0; i < moduleTypes.Length; i++)
5453
{
5554
int length = moduleTypes[i].Length;
5655
Array.Copy(moduleTypes[i], 0, ret, current, length);

src/System.Private.CoreLib/src/System/Runtime/CompilerServices/ConditionalWeakTable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ internal Container Resize(int newSize)
528528
// Reallocate both buckets and entries and rebuild the bucket and entries from scratch.
529529
// This serves both to scrub entries with expired keys and to put the new entries in the proper bucket.
530530
int[] newBuckets = new int[newSize];
531-
for (int bucketIndex = 0; bucketIndex < newSize; bucketIndex++)
531+
for (int bucketIndex = 0; bucketIndex < newBuckets.Length; bucketIndex++)
532532
{
533533
newBuckets[bucketIndex] = -1;
534534
}

0 commit comments

Comments
 (0)