[Python-Dev] PEP 275: Switching on Multiple Values, Rev 1.2
M.-A. Lemburg
mal@lemburg.com
Fri, 23 Nov 2001 14:47:10 +0100
Aahz Maruch wrote:
>
> Here's a weird idea:
>
> Given that the main problem we're trying to solve is the slowness of
> dictionary dispatching to functions, how about adding an "inline"
> keyword or function?
Because AFAIK inlining in Python is just as expensive as doing
a Python function call: you have to merge all constants, locals,
etc. Depending on the function signature, it may not even be
possible (e.g. if parameters don't match the inling function's
signature).
> For example (assuming it's a function):
>
> def handle_data():
> self.append(data)
>
> dispatch_dict["foo"] = handle_data
>
> class C:
> def read_input(self):
> data = "foo"
> value = handle_data
> inline(dispatch_dict[value])
>
> Note carefully that handle_data() has no paramaters. This solution
> would be somewhat more expensive computationally than the switch
> construct, but it ought to be cheaper than doing an actual function
> call.
--
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Consulting & Company: http://www.egenix.com/
Python Software: http://www.lemburg.com/python/