Skip to content

Commit f8e5d25

Browse files
authored
Made allocCount const where possible. (#296)
1 parent 32aac52 commit f8e5d25

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

src/Function.Wrap.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public partial class Function
4444
// Fetch a converter for each parameter type to box it
4545

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

4949
Action result = () =>
5050
{
@@ -91,7 +91,7 @@ public partial class Function
9191
var convT = ValueRaw.Converter<T>();
9292

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

9696
Action<T> result = (p0) =>
9797
{
@@ -140,7 +140,7 @@ public partial class Function
140140
var convT2 = ValueRaw.Converter<T2>();
141141

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

745745
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) =>
746746
{
@@ -811,7 +811,7 @@ public partial class Function
811811
var convT13 = ValueRaw.Converter<T13>();
812812

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

816816
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) =>
817817
{
@@ -884,7 +884,7 @@ public partial class Function
884884
var convT14 = ValueRaw.Converter<T14>();
885885

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

889889
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) =>
890890
{
@@ -959,7 +959,7 @@ public partial class Function
959959
var convT15 = ValueRaw.Converter<T15>();
960960

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

964964
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) =>
965965
{
@@ -1036,7 +1036,7 @@ public partial class Function
10361036
var convT16 = ValueRaw.Converter<T16>();
10371037

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

10411041
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) =>
10421042
{

src/Function.Wrap.tt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,18 @@ var parameterTypes = new Type[] { <#= callbackParameterTypeExpressions #>};
7979
}
8080
#>
8181
// Determine how much space to allocate for params/results
82+
<#
83+
if (returnTypeCount == 0)
84+
{
85+
#>
86+
const int allocCount = <#= parameterCount.ToString(CultureInfo.InvariantCulture) #>;
87+
<#
88+
} else {
89+
#>
8290
var allocCount = Math.Max(<#= parameterCount.ToString(CultureInfo.InvariantCulture) #>, Results.Count);
91+
<#
92+
}
93+
#>
8394

8495
<#= delegateType #> result = (<#
8596
for (int x = 0; x < parameterCount; x++)

0 commit comments

Comments
 (0)