For a language that is optimised at compile time your suggestion is a very good one, since it allows a useful optimisation.
For a language that is optimised at runtime, like Java, they can recognise the local function and do the optimisation anyway. If you see the benchmark I wrote above the current release of Java is almost as fast with heap allocation as stack allocation and in the next version they are adding escape analysis. Escape analysis looks for pointers that escape the local context, e.g. your onEvent example, and these it leaves alone. But the pointers that don't excape it allocates on the stack, therefore they can do the optimisation in J6 automatically without requiring the extra keyword.
Flat View: This topic has 30 replies
on 3 pages