1
1
using System ;
2
+ using System . Linq ;
2
3
using System . Reflection ;
3
4
using System . Runtime . CompilerServices ;
4
5
using System . Threading . Tasks ;
5
6
6
7
using BenchmarkDotNet . Extensions ;
7
8
using BenchmarkDotNet . Running ;
8
9
9
- using JetBrains . Annotations ;
10
-
11
10
namespace BenchmarkDotNet . Toolchains . InProcess . NoEmit
12
11
{
13
12
/// <summary>Helper class that creates <see cref="BenchmarkAction"/> instances. </summary>
@@ -29,9 +28,40 @@ private static BenchmarkAction CreateCore(
29
28
if ( resultType == typeof ( void ) )
30
29
return new BenchmarkActionVoid ( resultInstance , targetMethod , unrollFactor ) ;
31
30
31
+ if ( resultType == typeof ( void * ) )
32
+ return new BenchmarkActionVoidPointer ( resultInstance , targetMethod , unrollFactor ) ;
33
+
34
+ if ( resultType . IsPointer )
35
+ return Create (
36
+ typeof ( BenchmarkActionPointer < > ) . MakeGenericType ( resultType . GetElementType ( ) ) ,
37
+ resultInstance ,
38
+ targetMethod ,
39
+ unrollFactor ) ;
40
+
41
+ if ( resultType . IsByRef )
42
+ {
43
+ var returnParameter = targetMethod ? . ReturnParameter ?? fallbackIdleSignature . ReturnParameter ;
44
+ // System.Runtime.CompilerServices.IsReadOnlyAttribute is part of .NET Standard 2.1, we can't use it here..
45
+ if ( returnParameter . GetCustomAttributes ( ) . Any ( attribute => attribute . GetType ( ) . Name == "IsReadOnlyAttribute" ) )
46
+ return Create (
47
+ typeof ( BenchmarkActionByRefReadonly < > ) . MakeGenericType ( resultType . GetElementType ( ) ) ,
48
+ resultInstance ,
49
+ targetMethod ,
50
+ unrollFactor ) ;
51
+
52
+ return Create (
53
+ typeof ( BenchmarkActionByRef < > ) . MakeGenericType ( resultType . GetElementType ( ) ) ,
54
+ resultInstance ,
55
+ targetMethod ,
56
+ unrollFactor ) ;
57
+ }
58
+
32
59
if ( resultType == typeof ( Task ) )
33
60
return new BenchmarkActionTask ( resultInstance , targetMethod , unrollFactor ) ;
34
61
62
+ if ( resultType == typeof ( ValueTask ) )
63
+ return new BenchmarkActionValueTask ( resultInstance , targetMethod , unrollFactor ) ;
64
+
35
65
if ( resultType . GetTypeInfo ( ) . IsGenericType )
36
66
{
37
67
var genericType = resultType . GetGenericTypeDefinition ( ) ;
@@ -51,10 +81,6 @@ private static BenchmarkAction CreateCore(
51
81
unrollFactor ) ;
52
82
}
53
83
54
- if ( targetMethod == null && resultType . GetTypeInfo ( ) . IsValueType )
55
- // for Idle: we return int because creating bigger ValueType could take longer than benchmarked method itself.
56
- resultType = typeof ( int ) ;
57
-
58
84
return Create (
59
85
typeof ( BenchmarkAction < > ) . MakeGenericType ( resultType ) ,
60
86
resultInstance ,
@@ -88,6 +114,10 @@ private static void PrepareInstanceAndResultType(
88
114
if ( isUsingAsyncKeyword )
89
115
throw new NotSupportedException ( "Async void is not supported by design." ) ;
90
116
}
117
+ else if ( resultType . IsByRefLike ( ) || resultType ? . GetElementType ( ) ? . IsByRefLike ( ) == true )
118
+ {
119
+ throw new NotSupportedException ( "InProcessNoEmitToolchain does not support consuming ByRefLike return types." ) ;
120
+ }
91
121
}
92
122
93
123
/// <summary>Helper to enforce .ctor signature.</summary>
0 commit comments