From 2ea4ec2992fe2f9935f6c3c1448c38e142298fc1 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 15 Dec 2017 04:30:19 +0000 Subject: [PATCH] Drop range check --- .../shared/System/Collections/Generic/Dictionary.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/mscorlib/shared/System/Collections/Generic/Dictionary.cs b/src/mscorlib/shared/System/Collections/Generic/Dictionary.cs index fb831737d416..8903f1ac3ad0 100644 --- a/src/mscorlib/shared/System/Collections/Generic/Dictionary.cs +++ b/src/mscorlib/shared/System/Collections/Generic/Dictionary.cs @@ -371,15 +371,18 @@ private int FindEntry(TKey key) i = buckets[hashCode % buckets.Length]; Entry[] entries = _entries; - while (i >= 0) + do { if (entries[i].hashCode == hashCode && comparer.Equals(entries[i].key, key)) + // Should be a while loop https://github.com/dotnet/coreclr/issues/15476 + // Test in if to drop range check for following array access + if ((uint)i >= (uint)entries.Length || (entries[i].hashCode == hashCode && comparer.Equals(entries[i].key, key))) { break; } i = entries[i].next; - } + } while (true); } return i; }