[pypy-dev] call_function

Armin Rigo arigo at tunes.org
Fri Dec 16 17:56:38 CET 2005

Hi Ben,

On Fri, Dec 16, 2005 at 04:24:09PM +0000, Ben.Young at risk.sungard.com wrote:
>     def CALL_FUNCTION(f, oparg):
>         if oparg & 0xff == oparg: 
>             w_function = f.valuestack.pop()
>                 #pseudo code
>                 w_args = f.valuestack.pop(oparg)
>             w_result = f.space.call_function(w_function, *w_args)
>             f.valuestack.push(w_result)
>         else:
>             # general case
>             f.call_function(oparg)
> Doesn't this do the same thing? f.space.call_function seems to be able to 
> handle any number of positional args.

Well, the real code you are quoting contains comment "XXX start of hack
for performance" and "XXX end of hack for performance" around the first
part.  Indeed, none of this is necessary.  It does give a good
performance boost, though, because it avoids having to build a list from
the arguments popped off the start.

If you are confused by space.call_function() containing *again* a list
of if/elif fast paths, remember that in the C version there are
different versions of space.call_function() created, one for each number
of argument (we do this for all *arg functions).  In each version, each
if/elif condition is known at compile-time, so only one of the branches
is left.  It's not actually testing again the number of arguments at

A bientot,


More information about the Pypy-dev mailing list