1
1
<#@ output extension=".tt.cs" #>
2
+ <#@ import namespace="System.Linq" #>
2
3
using System;
3
- using System.Buffers;
4
- namespace Pchp.Core;
5
- using System.Runtime.CompilerServices;
6
4
using System.Runtime.InteropServices;
5
+ namespace Pchp.Core;
6
+
7
+
7
8
8
9
partial interface IPhpCallable
9
10
{
@@ -22,6 +23,8 @@ partial interface IPhpCallable
22
23
for(int arity = 2; arity <= 16; arity++)
23
24
{
24
25
#>
26
+
27
+
25
28
/// <summary>
26
29
/// Invokes the callback with given arguments.
27
30
/// Uses ArrayPool to avoid allocation.
@@ -33,21 +36,30 @@ partial interface IPhpCallable
33
36
<# } #>
34
37
PhpValue p<#= arity - 1 #>)
35
38
{
36
- var phpArgs = ArrayPool<PhpValue>.Shared.Rent(<#= arity #>);
37
- try
39
+
40
+ var tuple = new PhpArgTuple<#= arity #>
38
41
{
39
42
<# for(int p = 0; p < arity; p++) { #>
40
- phpArgs[ <#= p #>] = p<#= p #>;
43
+ Argument <#= p #> = p<#= p #>,
41
44
<# } #>
42
- return Invoke(ctx, new ReadOnlySpan<PhpValue>(phpArgs, 0, <#= arity #>));
43
- }
44
- finally
45
- {
46
- ArrayPool<PhpValue>.Shared.Return(phpArgs, true);
47
- }
45
+ };
46
+ var phpArgs = MemoryMarshal.CreateSpan(ref tuple.Argument0, <#= arity #>);
47
+ return Invoke(ctx, phpArgs);
48
48
}
49
49
50
50
<#
51
51
}
52
+
53
+ for (int arity = 2; arity <= 16; arity++)
54
+ {#>
55
+ [StructLayout(LayoutKind.Sequential)]
56
+ private struct PhpArgTuple<#= arity #>
57
+ {
58
+ <# for(int p = 0; p < arity; p++) { #>
59
+ public PhpValue Argument<#= p #>;
60
+ <# } #>
61
+ }
62
+ <#
63
+ }
52
64
#>
53
65
}
0 commit comments