summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaryam Ariyan <maryam.ariyan@microsoft.com>2018-01-29 17:35:21 -0500
committerGitHub <noreply@github.com>2018-01-29 17:35:21 -0500
commitb02961001f1978437f7bd5ba7c6d9a2c3da3c088 (patch)
tree9a71ac62ca4050bfed036f1f62a1ee253bda2712
parent8d8f5da892f89a50a55715fb59ca73abfa13ee90 (diff)
downloadcoreclr-b02961001f1978437f7bd5ba7c6d9a2c3da3c088.tar.gz
coreclr-b02961001f1978437f7bd5ba7c6d9a2c3da3c088.tar.bz2
coreclr-b02961001f1978437f7bd5ba7c6d9a2c3da3c088.zip
EnsureCapacty(0) should return zero as capacity for a non initialized Dictionary rather than doing initialization. (#16076)
Issue is: dotnet/corefx#24445
-rw-r--r--src/mscorlib/shared/System/Collections/Generic/Dictionary.cs5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/mscorlib/shared/System/Collections/Generic/Dictionary.cs b/src/mscorlib/shared/System/Collections/Generic/Dictionary.cs
index ed033f3cf8..24eaa0d12d 100644
--- a/src/mscorlib/shared/System/Collections/Generic/Dictionary.cs
+++ b/src/mscorlib/shared/System/Collections/Generic/Dictionary.cs
@@ -768,8 +768,9 @@ namespace System.Collections.Generic
{
if (capacity < 0)
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity);
- if (_entries != null && _entries.Length >= capacity)
- return _entries.Length;
+ int currentCapacity = _entries == null ? 0 : _entries.Length;
+ if (currentCapacity >= capacity)
+ return currentCapacity;
if (_buckets == null)
return Initialize(capacity);
int newSize = HashHelpers.GetPrime(capacity);