Skip to content

Commit

Permalink
Made allocCount const where possible. (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
martindevans authored Jan 26, 2024
1 parent 32aac52 commit f8e5d25
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/Function.Wrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public partial class Function
// Fetch a converter for each parameter type to box it

// Determine how much space to allocate for params/results
var allocCount = Math.Max(0, Results.Count);
const int allocCount = 0;

Action result = () =>
{
Expand Down Expand Up @@ -91,7 +91,7 @@ public partial class Function
var convT = ValueRaw.Converter<T>();

// Determine how much space to allocate for params/results
var allocCount = Math.Max(1, Results.Count);
const int allocCount = 1;

Action<T> result = (p0) =>
{
Expand Down Expand Up @@ -140,7 +140,7 @@ public partial class Function
var convT2 = ValueRaw.Converter<T2>();

// Determine how much space to allocate for params/results
var allocCount = Math.Max(2, Results.Count);
const int allocCount = 2;

Action<T1, T2> result = (p0, p1) =>
{
Expand Down Expand Up @@ -191,7 +191,7 @@ public partial class Function
var convT3 = ValueRaw.Converter<T3>();

// Determine how much space to allocate for params/results
var allocCount = Math.Max(3, Results.Count);
const int allocCount = 3;

Action<T1, T2, T3> result = (p0, p1, p2) =>
{
Expand Down Expand Up @@ -244,7 +244,7 @@ public partial class Function
var convT4 = ValueRaw.Converter<T4>();

// Determine how much space to allocate for params/results
var allocCount = Math.Max(4, Results.Count);
const int allocCount = 4;

Action<T1, T2, T3, T4> result = (p0, p1, p2, p3) =>
{
Expand Down Expand Up @@ -299,7 +299,7 @@ public partial class Function
var convT5 = ValueRaw.Converter<T5>();

// Determine how much space to allocate for params/results
var allocCount = Math.Max(5, Results.Count);
const int allocCount = 5;

Action<T1, T2, T3, T4, T5> result = (p0, p1, p2, p3, p4) =>
{
Expand Down Expand Up @@ -356,7 +356,7 @@ public partial class Function
var convT6 = ValueRaw.Converter<T6>();

// Determine how much space to allocate for params/results
var allocCount = Math.Max(6, Results.Count);
const int allocCount = 6;

Action<T1, T2, T3, T4, T5, T6> result = (p0, p1, p2, p3, p4, p5) =>
{
Expand Down Expand Up @@ -415,7 +415,7 @@ public partial class Function
var convT7 = ValueRaw.Converter<T7>();

// Determine how much space to allocate for params/results
var allocCount = Math.Max(7, Results.Count);
const int allocCount = 7;

Action<T1, T2, T3, T4, T5, T6, T7> result = (p0, p1, p2, p3, p4, p5, p6) =>
{
Expand Down Expand Up @@ -476,7 +476,7 @@ public partial class Function
var convT8 = ValueRaw.Converter<T8>();

// Determine how much space to allocate for params/results
var allocCount = Math.Max(8, Results.Count);
const int allocCount = 8;

Action<T1, T2, T3, T4, T5, T6, T7, T8> result = (p0, p1, p2, p3, p4, p5, p6, p7) =>
{
Expand Down Expand Up @@ -539,7 +539,7 @@ public partial class Function
var convT9 = ValueRaw.Converter<T9>();

// Determine how much space to allocate for params/results
var allocCount = Math.Max(9, Results.Count);
const int allocCount = 9;

Action<T1, T2, T3, T4, T5, T6, T7, T8, T9> result = (p0, p1, p2, p3, p4, p5, p6, p7, p8) =>
{
Expand Down Expand Up @@ -604,7 +604,7 @@ public partial class Function
var convT10 = ValueRaw.Converter<T10>();

// Determine how much space to allocate for params/results
var allocCount = Math.Max(10, Results.Count);
const int allocCount = 10;

Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> result = (p0, p1, p2, p3, p4, p5, p6, p7, p8, p9) =>
{
Expand Down Expand Up @@ -671,7 +671,7 @@ public partial class Function
var convT11 = ValueRaw.Converter<T11>();

// Determine how much space to allocate for params/results
var allocCount = Math.Max(11, Results.Count);
const int allocCount = 11;

Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> result = (p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) =>
{
Expand Down Expand Up @@ -740,7 +740,7 @@ public partial class Function
var convT12 = ValueRaw.Converter<T12>();

// Determine how much space to allocate for params/results
var allocCount = Math.Max(12, Results.Count);
const int allocCount = 12;

Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> result = (p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11) =>
{
Expand Down Expand Up @@ -811,7 +811,7 @@ public partial class Function
var convT13 = ValueRaw.Converter<T13>();

// Determine how much space to allocate for params/results
var allocCount = Math.Max(13, Results.Count);
const int allocCount = 13;

Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> result = (p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12) =>
{
Expand Down Expand Up @@ -884,7 +884,7 @@ public partial class Function
var convT14 = ValueRaw.Converter<T14>();

// Determine how much space to allocate for params/results
var allocCount = Math.Max(14, Results.Count);
const int allocCount = 14;

Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> result = (p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13) =>
{
Expand Down Expand Up @@ -959,7 +959,7 @@ public partial class Function
var convT15 = ValueRaw.Converter<T15>();

// Determine how much space to allocate for params/results
var allocCount = Math.Max(15, Results.Count);
const int allocCount = 15;

Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> result = (p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14) =>
{
Expand Down Expand Up @@ -1036,7 +1036,7 @@ public partial class Function
var convT16 = ValueRaw.Converter<T16>();

// Determine how much space to allocate for params/results
var allocCount = Math.Max(16, Results.Count);
const int allocCount = 16;

Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> result = (p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15) =>
{
Expand Down
11 changes: 11 additions & 0 deletions src/Function.Wrap.tt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,18 @@ var parameterTypes = new Type[] { <#= callbackParameterTypeExpressions #>};
}
#>
// Determine how much space to allocate for params/results
<#
if (returnTypeCount == 0)
{
#>
const int allocCount = <#= parameterCount.ToString(CultureInfo.InvariantCulture) #>;
<#
} else {
#>
var allocCount = Math.Max(<#= parameterCount.ToString(CultureInfo.InvariantCulture) #>, Results.Count);
<#
}
#>

<#= delegateType #> result = (<#
for (int x = 0; x < parameterCount; x++)
Expand Down

0 comments on commit f8e5d25

Please sign in to comment.