# HG changeset patch # User Paul Boddie # Date 1488755627 -3600 # Node ID 124ed76ca4a8dd563d9c6f4767861a3125c1d750 # Parent fc5943513f3a54ee8014514ef444a2be38045d78 Optimise the common case of having all positional parameters as arguments. diff -r fc5943513f3a -r 124ed76ca4a8 templates/progops.c --- a/templates/progops.c Sun Mar 05 23:06:54 2017 +0100 +++ b/templates/progops.c Mon Mar 06 00:13:47 2017 +0100 @@ -197,7 +197,7 @@ /* Reserve enough space for the arguments. */ - __attr allargs[max]; + __attr *allargs = args, moreargs[max]; /* Traverse the arguments. */ @@ -211,39 +211,44 @@ /* Copy the arguments. */ - for (pos = 0; pos < nargs; pos++) - allargs[pos] = args[pos]; + if (nargs < max) + { + allargs = moreargs; - /* Erase the remaining arguments. */ + for (pos = 0; pos < nargs; pos++) + allargs[pos] = args[pos]; + + /* Erase the remaining arguments. */ - for (pos = nargs; pos < max; pos++) - allargs[pos].value = 0; + for (pos = nargs; pos < max; pos++) + allargs[pos].value = 0; - /* Fill keyword arguments. */ + /* Fill keyword arguments. */ - for (kwpos = 0; kwpos < nkwargs; kwpos++) - { - pos = __HASPARAM(ptable, kwcodes[kwpos].pos, kwcodes[kwpos].code); + for (kwpos = 0; kwpos < nkwargs; kwpos++) + { + pos = __HASPARAM(ptable, kwcodes[kwpos].pos, kwcodes[kwpos].code); - /* Check the table entry against the supplied argument details. - Set the argument but only if it does not overwrite positional - arguments. */ - /* NOTE: Should use a more specific exception. */ + /* Check the table entry against the supplied argument details. + Set the argument but only if it does not overwrite positional + arguments. */ + /* NOTE: Should use a more specific exception. */ - if ((pos == -1) || (pos < nargs)) - __raise_type_error(); + if ((pos == -1) || (pos < nargs)) + __raise_type_error(); - /* Set the argument using the appropriate position. */ + /* Set the argument using the appropriate position. */ - allargs[pos] = kwargs[kwpos]; - } + allargs[pos] = kwargs[kwpos]; + } - /* Fill the defaults. */ + /* Fill the defaults. */ - for (pos = nargs; pos < max; pos++) - { - if (allargs[pos].value == 0) - allargs[pos] = __GETDEFAULT(target.value, pos - min); + for (pos = nargs; pos < max; pos++) + { + if (allargs[pos].value == 0) + allargs[pos] = __GETDEFAULT(target.value, pos - min); + } } /* Call with the prepared arguments. */