From: Tarun Pothulapati Date: Fri, 5 May 2017 17:49:59 +0000 (+0000) Subject: Removed Dictionary.GetValueOrDefault Methods (dotnet/coreclr#11388) X-Git-Tag: submit/tizen/20210909.063632~11030^2~7005 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3515d207ecff193934c636de4ab16d125eac1a4c;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Removed Dictionary.GetValueOrDefault Methods (dotnet/coreclr#11388) * 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 --- diff --git a/src/coreclr/src/mscorlib/src/System/Collections/Generic/Dictionary.cs b/src/coreclr/src/mscorlib/src/System/Collections/Generic/Dictionary.cs index e360eef..ddf3099 100644 --- a/src/coreclr/src/mscorlib/src/System/Collections/Generic/Dictionary.cs +++ b/src/coreclr/src/mscorlib/src/System/Collections/Generic/Dictionary.cs @@ -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>.IsReadOnly diff --git a/src/coreclr/src/mscorlib/src/System/Reflection/CustomAttribute.cs b/src/coreclr/src/mscorlib/src/System/Reflection/CustomAttribute.cs index 96eb45f..0f0c052 100644 --- a/src/coreclr/src/mscorlib/src/System/Reflection/CustomAttribute.cs +++ b/src/coreclr/src/mscorlib/src/System/Reflection/CustomAttribute.cs @@ -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(); List pcas = new List(); @@ -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(); List pcas = new List(); @@ -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(); List pcas = new List(); @@ -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(); List pcas = new List(); @@ -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)) diff --git a/src/coreclr/src/mscorlib/src/System/RtType.cs b/src/coreclr/src/mscorlib/src/System/RtType.cs index 6d0aa6f..3ae2e04 100644 --- a/src/coreclr/src/mscorlib/src/System/RtType.cs +++ b/src/coreclr/src/mscorlib/src/System/RtType.cs @@ -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 cache = csPropertyInfos.GetValueOrDefault(name); - - if (cache == null) + List cache; + if (!csPropertyInfos.TryGetValue(name, out cache)) { cache = new List(1); csPropertyInfos[name] = cache;