Removed Dictionary<TKey, TValue>.GetValueOrDefault Methods (dotnet/coreclr#11388)
authorTarun Pothulapati <tarunpothulapati@outlook.com>
Fri, 5 May 2017 17:49:59 +0000 (17:49 +0000)
committerJan Kotas <jkotas@microsoft.com>
Fri, 5 May 2017 17:49:59 +0000 (10:49 -0700)
* Removed Dictionary.GetValueOrDefault Methods and the method calls in Rtpe.cs,CustomAttribute.cs

* Replaced the Dictionary.GetValueOrDefault Methods

* Used !s_pca.ContainsKey(caType) instead of s_pca.ContainsKey(caType) == false

Commit migrated from https://github.com/dotnet/coreclr/commit/0581f34ca9b0cd27abf03a4d0232ca59250ab9f0

src/coreclr/src/mscorlib/src/System/Collections/Generic/Dictionary.cs
src/coreclr/src/mscorlib/src/System/Reflection/CustomAttribute.cs
src/coreclr/src/mscorlib/src/System/RtType.cs

index e360eef..ddf3099 100644 (file)
@@ -706,22 +706,6 @@ namespace System.Collections.Generic
             value = default(TValue);
             return false;
         }
-
-        // Method similar to TryGetValue that returns the value instead of putting it in an out param.
-        public TValue GetValueOrDefault(TKey key) => GetValueOrDefault(key, default(TValue));
-
-        // Method similar to TryGetValue that returns the value instead of putting it in an out param. If the entry
-        // doesn't exist, returns the defaultValue instead.
-        public TValue GetValueOrDefault(TKey key, TValue defaultValue)
-        {
-            int i = FindEntry(key);
-            if (i >= 0)
-            {
-                return entries[i].value;
-            }
-            return defaultValue;
-        }
-
         public bool TryAdd(TKey key, TValue value) => TryInsert(key, value, InsertionBehavior.None);
 
         bool ICollection<KeyValuePair<TKey, TValue>>.IsReadOnly
index 96eb45f..0f0c052 100644 (file)
@@ -2040,7 +2040,7 @@ namespace System.Reflection
             count = 0;
 
             bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute);
-            if (!all && s_pca.GetValueOrDefault(caType) == null && !IsSecurityAttribute(caType))
+            if (!all && !s_pca.ContainsKey(caType) && !IsSecurityAttribute(caType))
                 return Array.Empty<Attribute>();
 
             List<Attribute> pcas = new List<Attribute>();
@@ -2078,7 +2078,7 @@ namespace System.Reflection
         internal static bool IsDefined(RuntimeType type, RuntimeType caType)
         {
             bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute);
-            if (!all && s_pca.GetValueOrDefault(caType) == null && !IsSecurityAttribute(caType))
+            if (!all && !s_pca.ContainsKey(caType) && !IsSecurityAttribute(caType))
                 return false;
 
             if (all || caType == (RuntimeType)typeof(SerializableAttribute))
@@ -2107,7 +2107,7 @@ namespace System.Reflection
             count = 0;
 
             bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute);
-            if (!all && s_pca.GetValueOrDefault(caType) == null && !IsSecurityAttribute(caType))
+            if (!all && !s_pca.ContainsKey(caType) && !IsSecurityAttribute(caType))
                 return Array.Empty<Attribute>();
 
             List<Attribute> pcas = new List<Attribute>();
@@ -2140,7 +2140,7 @@ namespace System.Reflection
         internal static bool IsDefined(RuntimeMethodInfo method, RuntimeType caType)
         {
             bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute);
-            if (!all && s_pca.GetValueOrDefault(caType) == null)
+            if (!all && !s_pca.ContainsKey(caType))
                 return false;
 
             if (all || caType == (RuntimeType)typeof(DllImportAttribute))
@@ -2170,7 +2170,7 @@ namespace System.Reflection
             count = 0;
 
             bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute);
-            if (!all && s_pca.GetValueOrDefault(caType) == null)
+            if (!all && !s_pca.ContainsKey(caType))
                 return null;
 
             Attribute[] pcas = new Attribute[s_pcasCount];
@@ -2201,7 +2201,7 @@ namespace System.Reflection
         internal static bool IsDefined(RuntimeParameterInfo parameter, RuntimeType caType)
         {
             bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute);
-            if (!all && s_pca.GetValueOrDefault(caType) == null)
+            if (!all && !s_pca.ContainsKey(caType))
                 return false;
 
 
@@ -2231,7 +2231,7 @@ namespace System.Reflection
 
             bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute);
 
-            if (!all && s_pca.GetValueOrDefault(caType) == null && !IsSecurityAttribute(caType))
+            if (!all && !s_pca.ContainsKey(caType) && !IsSecurityAttribute(caType))
                 return Array.Empty<Attribute>();
 
             List<Attribute> pcas = new List<Attribute>();
@@ -2283,7 +2283,7 @@ namespace System.Reflection
             count = 0;
 
             bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute);
-            if (!all && s_pca.GetValueOrDefault(caType) == null)
+            if (!all && !s_pca.ContainsKey(caType))
                 return null;
 
             Attribute[] pcas = new Attribute[s_pcasCount];
@@ -2309,7 +2309,7 @@ namespace System.Reflection
         internal static bool IsDefined(RuntimeFieldInfo field, RuntimeType caType)
         {
             bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute);
-            if (!all && s_pca.GetValueOrDefault(caType) == null)
+            if (!all && !s_pca.ContainsKey(caType))
                 return false;
 
             if (all || caType == (RuntimeType)typeof(MarshalAsAttribute))
@@ -2334,7 +2334,7 @@ namespace System.Reflection
 
             bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute);
 
-            if (!all && s_pca.GetValueOrDefault(caType) == null && !IsSecurityAttribute(caType))
+            if (!all && !s_pca.ContainsKey(caType) && !IsSecurityAttribute(caType))
                 return Array.Empty<Attribute>();
 
             List<Attribute> pcas = new List<Attribute>();
@@ -2357,7 +2357,7 @@ namespace System.Reflection
         {
             bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute);
 
-            if (!all && s_pca.GetValueOrDefault(caType) == null)
+            if (!all && !s_pca.ContainsKey(caType))
                 return false;
 
             if (all || IsSecurityAttribute(caType))
index 6d0aa6f..3ae2e04 100644 (file)
@@ -1200,7 +1200,7 @@ namespace System
                         {
                             string name = eventInfo.Name;
 
-                            if (csEventInfos.GetValueOrDefault(name) != null)
+                            if (csEventInfos.ContainsKey(name))
                                 continue;
 
                             csEventInfos[name] = eventInfo;
@@ -1355,10 +1355,8 @@ namespace System
                             if (csPropertyInfos != null)
                             {
                                 string name = propertyInfo.Name;
-
-                                List<RuntimePropertyInfo> cache = csPropertyInfos.GetValueOrDefault(name);
-
-                                if (cache == null)
+                                List<RuntimePropertyInfo> cache;
+                                if (!csPropertyInfos.TryGetValue(name, out cache))
                                 {
                                     cache = new List<RuntimePropertyInfo>(1);
                                     csPropertyInfos[name] = cache;