@@ -40,14 +40,6 @@ internal abstract class DeclarationsProvider
4040
4141 public virtual string GetWorkloadMethodCall ( string passArguments ) => $ "{ Descriptor . WorkloadMethod . Name } ({ passArguments } )";
4242
43- public virtual string ConsumeField => null ;
44-
45- protected abstract Type OverheadMethodReturnType { get ; }
46-
47- public string OverheadMethodReturnTypeName => OverheadMethodReturnType . GetCorrectCSharpTypeName ( ) ;
48-
49- public abstract string OverheadImplementation { get ; }
50-
5143 private string GetMethodName ( MethodInfo method )
5244 {
5345 if ( method == null )
@@ -73,62 +65,21 @@ internal class VoidDeclarationsProvider : DeclarationsProvider
7365 public VoidDeclarationsProvider ( Descriptor descriptor ) : base ( descriptor ) { }
7466
7567 public override string ReturnsDefinition => "RETURNS_VOID" ;
76-
77- protected override Type OverheadMethodReturnType => typeof ( void ) ;
78-
79- public override string OverheadImplementation => string . Empty ;
8068 }
8169
8270 internal class NonVoidDeclarationsProvider : DeclarationsProvider
8371 {
8472 public NonVoidDeclarationsProvider ( Descriptor descriptor ) : base ( descriptor ) { }
8573
86- public override string ConsumeField
87- => ! Consumer . IsConsumable ( WorkloadMethodReturnType ) && Consumer . HasConsumableField ( WorkloadMethodReturnType , out var field )
88- ? $ ".{ field . Name } "
89- : null ;
90-
91- protected override Type OverheadMethodReturnType
92- => Consumer . IsConsumable ( WorkloadMethodReturnType )
93- ? WorkloadMethodReturnType
94- : ( Consumer . HasConsumableField ( WorkloadMethodReturnType , out var field )
95- ? field . FieldType
96- : typeof ( int ) ) ; // we return this simple type because creating bigger ValueType could take longer than benchmarked method itself
97-
98- public override string OverheadImplementation
99- {
100- get
101- {
102- string value ;
103- var type = OverheadMethodReturnType ;
104- if ( type . GetTypeInfo ( ) . IsPrimitive )
105- value = $ "default({ type . GetCorrectCSharpTypeName ( ) } )";
106- else if ( type . GetTypeInfo ( ) . IsClass || type . GetTypeInfo ( ) . IsInterface )
107- value = "null" ;
108- else
109- value = SourceCodeHelper . ToSourceCode ( Activator . CreateInstance ( type ) ) + ";" ;
110- return $ "return { value } ;";
111- }
112- }
113-
114- public override string ReturnsDefinition
115- => Consumer . IsConsumable ( WorkloadMethodReturnType ) || Consumer . HasConsumableField ( WorkloadMethodReturnType , out _ )
116- ? "RETURNS_CONSUMABLE"
117- : "RETURNS_NON_CONSUMABLE_STRUCT" ;
74+ public override string ReturnsDefinition => "RETURNS_NON_VOID" ;
11875 }
11976
12077 internal class ByRefDeclarationsProvider : NonVoidDeclarationsProvider
12178 {
12279 public ByRefDeclarationsProvider ( Descriptor descriptor ) : base ( descriptor ) { }
12380
124- protected override Type OverheadMethodReturnType => typeof ( IntPtr ) ;
125-
12681 public override string WorkloadMethodReturnTypeName => base . WorkloadMethodReturnTypeName . Replace ( "&" , string . Empty ) ;
12782
128- public override string ConsumeField => null ;
129-
130- public override string OverheadImplementation => $ "return default(System.{ nameof ( IntPtr ) } );";
131-
13283 public override string ReturnsDefinition => "RETURNS_BYREF" ;
13384
13485 public override string WorkloadMethodReturnTypeModifiers => "ref" ;
@@ -138,8 +89,6 @@ internal class ByReadOnlyRefDeclarationsProvider : ByRefDeclarationsProvider
13889 {
13990 public ByReadOnlyRefDeclarationsProvider ( Descriptor descriptor ) : base ( descriptor ) { }
14091
141- public override string ReturnsDefinition => "RETURNS_BYREF_READONLY" ;
142-
14392 public override string WorkloadMethodReturnTypeModifiers => "ref readonly" ;
14493 }
14594
0 commit comments