EnsureCapacty(0) should return zero as capacity for a non initialized Dictionary...
authorMaryam Ariyan <maryam.ariyan@microsoft.com>
Mon, 29 Jan 2018 22:35:21 +0000 (17:35 -0500)
committerGitHub <noreply@github.com>
Mon, 29 Jan 2018 22:35:21 +0000 (17:35 -0500)
Issue is: dotnet/corefx#24445

src/mscorlib/shared/System/Collections/Generic/Dictionary.cs

index ed033f3..24eaa0d 100644 (file)
@@ -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);