Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Delete redundant int pcaCount intializations
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas committed Feb 26, 2018
1 parent 41067e5 commit 3b7181a
Showing 1 changed file with 14 additions and 28 deletions.
42 changes: 14 additions & 28 deletions src/mscorlib/src/System/Reflection/CustomAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ internal static IList<CustomAttributeData> GetCustomAttributesInternal(RuntimeTy

IList<CustomAttributeData> cad = GetCustomAttributes(target.GetRuntimeModule(), target.MetadataToken);

int pcaCount = 0;
Attribute[] a = PseudoCustomAttribute.GetCustomAttributes((RuntimeType)target, typeof(object) as RuntimeType, out pcaCount);
Attribute[] a = PseudoCustomAttribute.GetCustomAttributes((RuntimeType)target, typeof(object) as RuntimeType, out int pcaCount);

if (pcaCount == 0)
return cad;
Expand All @@ -84,8 +83,7 @@ internal static IList<CustomAttributeData> GetCustomAttributesInternal(RuntimeFi

IList<CustomAttributeData> cad = GetCustomAttributes(target.GetRuntimeModule(), target.MetadataToken);

int pcaCount = 0;
Attribute[] a = PseudoCustomAttribute.GetCustomAttributes((RuntimeFieldInfo)target, typeof(object) as RuntimeType, out pcaCount);
Attribute[] a = PseudoCustomAttribute.GetCustomAttributes((RuntimeFieldInfo)target, typeof(object) as RuntimeType, out int pcaCount);

if (pcaCount == 0)
return cad;
Expand All @@ -106,8 +104,7 @@ internal static IList<CustomAttributeData> GetCustomAttributesInternal(RuntimeMe

IList<CustomAttributeData> cad = GetCustomAttributes(target.GetRuntimeModule(), target.MetadataToken);

int pcaCount = 0;
Attribute[] a = PseudoCustomAttribute.GetCustomAttributes((RuntimeMethodInfo)target, typeof(object) as RuntimeType, out pcaCount);
Attribute[] a = PseudoCustomAttribute.GetCustomAttributes((RuntimeMethodInfo)target, typeof(object) as RuntimeType, out int pcaCount);

if (pcaCount == 0)
return cad;
Expand Down Expand Up @@ -159,8 +156,7 @@ internal static IList<CustomAttributeData> GetCustomAttributesInternal(RuntimeAs

IList<CustomAttributeData> cad = GetCustomAttributes((RuntimeModule)target.ManifestModule, RuntimeAssembly.GetToken(target.GetNativeHandle()));

int pcaCount = 0;
Attribute[] a = PseudoCustomAttribute.GetCustomAttributes(target, typeof(object) as RuntimeType, out pcaCount);
Attribute[] a = PseudoCustomAttribute.GetCustomAttributes(target, typeof(object) as RuntimeType, out int pcaCount);

if (pcaCount == 0)
return cad;
Expand All @@ -181,8 +177,7 @@ internal static IList<CustomAttributeData> GetCustomAttributesInternal(RuntimePa

IList<CustomAttributeData> cad = GetCustomAttributes(target.GetRuntimeModule(), target.MetadataToken);

int pcaCount = 0;
Attribute[] a = PseudoCustomAttribute.GetCustomAttributes(target, typeof(object) as RuntimeType, out pcaCount);
Attribute[] a = PseudoCustomAttribute.GetCustomAttributes(target, typeof(object) as RuntimeType, out int pcaCount);

if (pcaCount == 0)
return cad;
Expand Down Expand Up @@ -1269,8 +1264,7 @@ internal static Object[] GetCustomAttributes(RuntimeType type, RuntimeType caTyp
if (type.IsGenericType && !type.IsGenericTypeDefinition)
type = type.GetGenericTypeDefinition() as RuntimeType;

int pcaCount = 0;
Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(type, caType, out pcaCount);
Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(type, caType, out int pcaCount);

// if we are asked to go up the hierarchy chain we have to do it now and regardless of the
// attribute usage for the specific attribute because a derived attribute may override the usage...
Expand Down Expand Up @@ -1313,8 +1307,7 @@ internal static Object[] GetCustomAttributes(RuntimeMethodInfo method, RuntimeTy
if (method.IsGenericMethod && !method.IsGenericMethodDefinition)
method = method.GetGenericMethodDefinition() as RuntimeMethodInfo;

int pcaCount = 0;
Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(method, caType, out pcaCount);
Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(method, caType, out int pcaCount);

// if we are asked to go up the hierarchy chain we have to do it now and regardless of the
// attribute usage for the specific attribute because a derived attribute may override the usage...
Expand Down Expand Up @@ -1354,8 +1347,7 @@ internal static Object[] GetCustomAttributes(RuntimeConstructorInfo ctor, Runtim
Debug.Assert(ctor != null);
Debug.Assert(caType != null);

int pcaCount = 0;
Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(ctor, caType, out pcaCount);
Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(ctor, caType, out int pcaCount);
object[] attributes = GetCustomAttributes(ctor.GetRuntimeModule(), ctor.MetadataToken, pcaCount, caType);
if (pcaCount > 0) Array.Copy(pca, 0, attributes, attributes.Length - pcaCount, pcaCount);
return attributes;
Expand All @@ -1366,8 +1358,7 @@ internal static Object[] GetCustomAttributes(RuntimePropertyInfo property, Runti
Debug.Assert(property != null);
Debug.Assert(caType != null);

int pcaCount = 0;
Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(property, caType, out pcaCount);
Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(property, caType, out int pcaCount);

object[] attributes = GetCustomAttributes(property.GetRuntimeModule(), property.MetadataToken, pcaCount, caType);
if (pcaCount > 0) Array.Copy(pca, 0, attributes, attributes.Length - pcaCount, pcaCount);
Expand All @@ -1379,8 +1370,7 @@ internal static Object[] GetCustomAttributes(RuntimeEventInfo e, RuntimeType caT
Debug.Assert(e != null);
Debug.Assert(caType != null);

int pcaCount = 0;
Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(e, caType, out pcaCount);
Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(e, caType, out int pcaCount);
object[] attributes = GetCustomAttributes(e.GetRuntimeModule(), e.MetadataToken, pcaCount, caType);
if (pcaCount > 0) Array.Copy(pca, 0, attributes, attributes.Length - pcaCount, pcaCount);
return attributes;
Expand All @@ -1391,8 +1381,7 @@ internal static Object[] GetCustomAttributes(RuntimeFieldInfo field, RuntimeType
Debug.Assert(field != null);
Debug.Assert(caType != null);

int pcaCount = 0;
Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(field, caType, out pcaCount);
Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(field, caType, out int pcaCount);
object[] attributes = GetCustomAttributes(field.GetRuntimeModule(), field.MetadataToken, pcaCount, caType);
if (pcaCount > 0) Array.Copy(pca, 0, attributes, attributes.Length - pcaCount, pcaCount);
return attributes;
Expand All @@ -1403,8 +1392,7 @@ internal static Object[] GetCustomAttributes(RuntimeParameterInfo parameter, Run
Debug.Assert(parameter != null);
Debug.Assert(caType != null);

int pcaCount = 0;
Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(parameter, caType, out pcaCount);
Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(parameter, caType, out int pcaCount);
object[] attributes = GetCustomAttributes(parameter.GetRuntimeModule(), parameter.MetadataToken, pcaCount, caType);
if (pcaCount > 0) Array.Copy(pca, 0, attributes, attributes.Length - pcaCount, pcaCount);
return attributes;
Expand All @@ -1415,8 +1403,7 @@ internal static Object[] GetCustomAttributes(RuntimeAssembly assembly, RuntimeTy
Debug.Assert(assembly != null);
Debug.Assert(caType != null);

int pcaCount = 0;
Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(assembly, caType, out pcaCount);
Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(assembly, caType, out int pcaCount);
int assemblyToken = RuntimeAssembly.GetToken(assembly.GetNativeHandle());
object[] attributes = GetCustomAttributes(assembly.ManifestModule as RuntimeModule, assemblyToken, pcaCount, caType);
if (pcaCount > 0) Array.Copy(pca, 0, attributes, attributes.Length - pcaCount, pcaCount);
Expand All @@ -1428,8 +1415,7 @@ internal static Object[] GetCustomAttributes(RuntimeModule module, RuntimeType c
Debug.Assert(module != null);
Debug.Assert(caType != null);

int pcaCount = 0;
Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(module, caType, out pcaCount);
Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(module, caType, out int pcaCount);
object[] attributes = GetCustomAttributes(module, module.MetadataToken, pcaCount, caType);
if (pcaCount > 0) Array.Copy(pca, 0, attributes, attributes.Length - pcaCount, pcaCount);
return attributes;
Expand Down

0 comments on commit 3b7181a

Please sign in to comment.