@@ -266,6 +266,9 @@ JL_CALLABLE(jl_f_apply)
266
266
jl_tuple_len (args [1 ]));
267
267
}
268
268
}
269
+ jl_value_t * argarr = NULL ;
270
+ JL_GC_PUSH1 (& argarr );
271
+ jl_value_t * result ;
269
272
jl_value_t * * newargs ;
270
273
size_t n = 0 , i , j ;
271
274
for (i = 1 ; i < nargs ; i ++ ) {
@@ -285,15 +288,27 @@ JL_CALLABLE(jl_f_apply)
285
288
JL_TYPECHK (apply , tuple , args [i ]);
286
289
}
287
290
}
288
- goto fancy_apply ;
291
+ argarr = jl_apply (jl_append_any_func , & args [1 ], nargs - 1 );
292
+ assert (jl_typeis (argarr , jl_array_any_type ));
293
+ result = jl_apply ((jl_function_t * )args [0 ], jl_cell_data (argarr ), jl_array_len (argarr ));
294
+ JL_GC_POP ();
295
+ return result ;
289
296
}
290
297
}
291
- newargs = (jl_value_t * * )alloca (n * sizeof (jl_value_t * ));
298
+ if (n > 64000 ) {
299
+ // put arguments on the heap if there are too many
300
+ argarr = (jl_value_t * )jl_alloc_cell_1d (n );
301
+ newargs = jl_cell_data (argarr );
302
+ }
303
+ else {
304
+ newargs = (jl_value_t * * )alloca (n * sizeof (jl_value_t * ));
305
+ }
292
306
n = 0 ;
293
307
for (i = 1 ; i < nargs ; i ++ ) {
294
308
if (jl_is_tuple (args [i ])) {
295
309
jl_tuple_t * t = (jl_tuple_t * )args [i ];
296
- for (j = 0 ; j < jl_tuple_len (t ); j ++ )
310
+ size_t al = jl_tuple_len (t );
311
+ for (j = 0 ; j < al ; j ++ )
297
312
newargs [n ++ ] = jl_tupleref (t , j );
298
313
}
299
314
else {
@@ -302,14 +317,7 @@ JL_CALLABLE(jl_f_apply)
302
317
newargs [n ++ ] = jl_cellref (args [i ], j );
303
318
}
304
319
}
305
- return jl_apply ((jl_function_t * )args [0 ], newargs , n );
306
-
307
- fancy_apply : ;
308
- jl_value_t * argarr = jl_apply (jl_append_any_func , & args [1 ], nargs - 1 );
309
- JL_GC_PUSH1 (& argarr );
310
- assert (jl_typeis (argarr , jl_array_any_type ));
311
- jl_value_t * result = jl_apply ((jl_function_t * )args [0 ],
312
- jl_cell_data (argarr ), jl_array_len (argarr ));
320
+ result = jl_apply ((jl_function_t * )args [0 ], newargs , n );
313
321
JL_GC_POP ();
314
322
return result ;
315
323
}
0 commit comments