File tree 3 files changed +13
-3
lines changed
Toolchains/InProcess/Emit/Implementation/Emitters
3 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,8 @@ public override string OverheadImplementation
90
90
get
91
91
{
92
92
var type = WorkloadMethodReturnType ;
93
- if ( type . IsByRefLike ( ) )
93
+ bool isByRefLike = type . IsByRefLike ( ) ;
94
+ if ( isByRefLike || ( Consumer . IsConsumable ( type ) && ! isByRefLike ) )
94
95
{
95
96
return $ "return default({ type . GetCorrectCSharpTypeName ( ) } );";
96
97
}
Original file line number Diff line number Diff line change @@ -12,6 +12,13 @@ namespace BenchmarkDotNet.Engines
12
12
{
13
13
public class Consumer
14
14
{
15
+ private static readonly HashSet < Type > SupportedTypes
16
+ = new HashSet < Type > (
17
+ typeof ( Consumer ) . GetTypeInfo ( )
18
+ . DeclaredFields
19
+ . Where ( field => ! field . IsStatic ) // exclude this HashSet itself
20
+ . Select ( field => field . FieldType ) ) ;
21
+
15
22
#pragma warning disable IDE0052 // Remove unread private members
16
23
private volatile byte byteHolder ;
17
24
private volatile sbyte sbyteHolder ;
@@ -123,7 +130,8 @@ public void Consume<T>(in T value)
123
130
// This also works for empty structs, because the runtime enforces a minimum size of 1 byte.
124
131
=> byteHolder = Unsafe . As < T , byte > ( ref Unsafe . AsRef ( in value ) ) ;
125
132
126
- internal static bool IsConsumable ( Type type ) => ! type . IsByRefLike ( ) ;
133
+ internal static bool IsConsumable ( Type type )
134
+ => SupportedTypes . Contains ( type ) || type . GetTypeInfo ( ) . IsClass || type . GetTypeInfo ( ) . IsInterface || ! type . IsByRefLike ( ) ;
127
135
128
136
internal static bool HasConsumableField ( Type type , out FieldInfo consumableField )
129
137
{
Original file line number Diff line number Diff line change @@ -80,7 +80,8 @@ protected override void OnEmitCtorBodyOverride(ConstructorBuilder constructorBui
80
80
81
81
public override void EmitOverheadImplementation ( ILGenerator ilBuilder , Type returnType )
82
82
{
83
- if ( returnType . IsByRefLike ( ) )
83
+ bool isByRefLike = returnType . IsByRefLike ( ) ;
84
+ if ( isByRefLike || ( Consumer . IsConsumable ( returnType ) && ! isByRefLike ) )
84
85
{
85
86
/*
86
87
// return default;
You can’t perform that action at this time.
0 commit comments