Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Peachpie.CodeAnalysis/Peachpie.CodeAnalysis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<OutputType>exe</OutputType>
<NoWarn>$(NoWarn);1591</NoWarn>
<NoWarn>$(NoWarn);1591;RS1009</NoWarn>
<AssemblyName>Peachpie.CodeAnalysis</AssemblyName>
<PackageId>Peachpie.CodeAnalysis</PackageId>
<PackageTags>php;peachpie;dotnet;compiler</PackageTags>
Expand Down
36 changes: 24 additions & 12 deletions src/Peachpie.Runtime/PhpCallable.ArrayPool.tt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<#@ output extension=".tt.cs" #>
<#@ import namespace="System.Linq" #>
using System;
using System.Buffers;
namespace Pchp.Core;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Pchp.Core;



partial interface IPhpCallable
{
Expand All @@ -22,6 +23,8 @@ partial interface IPhpCallable
for(int arity = 2; arity <= 16; arity++)
{
#>


/// <summary>
/// Invokes the callback with given arguments.
/// Uses ArrayPool to avoid allocation.
Expand All @@ -33,21 +36,30 @@ partial interface IPhpCallable
<# } #>
PhpValue p<#= arity - 1 #>)
{
var phpArgs = ArrayPool<PhpValue>.Shared.Rent(<#= arity #>);
try

var tuple = new PhpArgTuple<#= arity #>
{
<# for(int p = 0; p < arity; p++) { #>
phpArgs[<#= p #>] = p<#= p #>;
Argument<#= p #> = p<#= p #>,
<# } #>
return Invoke(ctx, new ReadOnlySpan<PhpValue>(phpArgs, 0, <#= arity #>));
}
finally
{
ArrayPool<PhpValue>.Shared.Return(phpArgs, true);
}
};
var phpArgs = MemoryMarshal.CreateReadOnlySpan(ref tuple.Argument0, <#= arity #>);
return Invoke(ctx, phpArgs);
}

<#
}

for (int arity = 2; arity <= 16; arity++)
{#>
[StructLayout(LayoutKind.Sequential)]
private struct PhpArgTuple<#= arity #>
{
<# for(int p = 0; p < arity; p++) { #>
public PhpValue Argument<#= p #>;
<# } #>
}
<#
}
#>
}
Loading
Loading