Skip to content

Commit

Permalink
Delete typeof caches from CoreLib (dotnet#76126)
Browse files Browse the repository at this point in the history
Caching typeof is a de-optimization with frozen runtime types
  • Loading branch information
jkotas authored Sep 24, 2022
1 parent aad5434 commit 3922b81
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -766,9 +766,6 @@ public CustomAttributeType(CustomAttributeEncoding encodedType, CustomAttributeE

internal static unsafe class CustomAttribute
{
private static readonly RuntimeType Type_RuntimeType = (RuntimeType)typeof(RuntimeType);
private static readonly RuntimeType Type_Type = (RuntimeType)typeof(Type);

#region Internal Static Members
internal static bool IsDefined(RuntimeType type, RuntimeType? caType, bool inherit)
{
Expand Down Expand Up @@ -1221,9 +1218,9 @@ private static void AddCustomAttributes(
if (type is null && value is not null)
{
type = (RuntimeType)value.GetType();
if (type == Type_RuntimeType)
if (type == typeof(RuntimeType))
{
type = Type_Type;
type = (RuntimeType)typeof(Type);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,6 @@ private static ParameterInfo[] GetParameters(
}
#endregion

#region Private Statics
private static readonly Type s_DecimalConstantAttributeType = typeof(DecimalConstantAttribute);
private static readonly Type s_CustomConstantAttributeType = typeof(CustomConstantAttribute);
#endregion

#region Private Data Members
private int m_tkParamDef;
private MetadataImport m_scope;
Expand Down Expand Up @@ -359,22 +354,22 @@ public override bool HasDefaultValue
{
defaultValue = GetRawDecimalConstant(attr);
}
else if (attrType!.IsSubclassOf(s_CustomConstantAttributeType))
else if (attrType!.IsSubclassOf(typeof(CustomConstantAttribute)))
{
defaultValue = GetRawConstant(attr);
}
}
}
else
{
object[] CustomAttrs = GetCustomAttributes(s_CustomConstantAttributeType, false);
object[] CustomAttrs = GetCustomAttributes(typeof(CustomConstantAttribute), false);
if (CustomAttrs.Length != 0)
{
defaultValue = ((CustomConstantAttribute)CustomAttrs[0]).Value;
}
else
{
CustomAttrs = GetCustomAttributes(s_DecimalConstantAttributeType, false);
CustomAttrs = GetCustomAttributes(typeof(DecimalConstantAttribute), false);
if (CustomAttrs.Length != 0)
{
defaultValue = ((DecimalConstantAttribute)CustomAttrs[0]).Value;
Expand Down

0 comments on commit 3922b81

Please sign in to comment.