Make MethodDesc.IsStaticConstructor more efficient (#79733)
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Fri, 16 Dec 2022 06:03:17 +0000 (15:03 +0900)
committerGitHub <noreply@github.com>
Fri, 16 Dec 2022 06:03:17 +0000 (15:03 +0900)
This is called a lot from reflection-dataflow-related places.

src/coreclr/tools/Common/TypeSystem/Common/InstantiatedMethod.cs
src/coreclr/tools/Common/TypeSystem/Common/MethodDelegator.cs
src/coreclr/tools/Common/TypeSystem/Common/MethodDesc.cs
src/coreclr/tools/Common/TypeSystem/Common/MethodForInstantiatedType.cs
src/coreclr/tools/Common/TypeSystem/Ecma/EcmaMethod.cs

index dce30da..0c4294d 100644 (file)
@@ -130,6 +130,14 @@ namespace Internal.TypeSystem
             }
         }
 
+        public override bool IsStaticConstructor
+        {
+            get
+            {
+                return false;
+            }
+        }
+
         public override MethodDesc GetMethodDefinition()
         {
             return _methodDef;
index b209123..74f218a 100644 (file)
@@ -24,6 +24,7 @@ namespace Internal.TypeSystem
         public override Instantiation Instantiation => _wrappedMethod.Instantiation;
 
         public override bool IsDefaultConstructor => _wrappedMethod.IsDefaultConstructor;
+        public override bool IsStaticConstructor => _wrappedMethod.IsStaticConstructor;
 
         public override string Name => _wrappedMethod.Name;
 
index 33af7a3..95218b9 100644 (file)
@@ -519,7 +519,7 @@ namespace Internal.TypeSystem
         /// <summary>
         /// Gets a value indicating whether this method is a static constructor.
         /// </summary>
-        public bool IsStaticConstructor
+        public virtual bool IsStaticConstructor
         {
             get
             {
index 30c3fe8..ff9df46 100644 (file)
@@ -127,6 +127,14 @@ namespace Internal.TypeSystem
             }
         }
 
+        public override bool IsStaticConstructor
+        {
+            get
+            {
+                return _typicalMethodDef.IsStaticConstructor;
+            }
+        }
+
         public override string Name
         {
             get
index 63eb97c..a0dbf5e 100644 (file)
@@ -370,6 +370,14 @@ namespace Internal.TypeSystem.Ecma
             }
         }
 
+        public override bool IsStaticConstructor
+        {
+            get
+            {
+                return Attributes.IsRuntimeSpecialName() && Name == ".cctor";
+            }
+        }
+
         public MethodAttributes Attributes
         {
             get