Memoize is used to change large/long-running subroutines into short/fast subroutines by caching results, and only for subroutines where there are no side effects, and all outputs can be computed solely from parameters. Reading from a database, for example, involves inputs that are not parameters, and thus fails this requirement.
The OP seems to be saying that there is an oft-called small routine that he would like to inline. That is something one would do with the "inline" keyword in C++, but in perl, you simply write a constant sub and hope that perl figures out that it's inlineable. Generally speaking, other than for constant, it hasn't sounded useful to me. So, these small routines are already small, and hopefully fast. I don't see that Memoize would be likely to be useful in a scenario where someone wants to remove even the overhead of a subroutine call.
Personally, I think what the OP is looking for is a source Filter that can take function definitions and put them into the code where they are called. For a single module, it shouldn't be too bad: just take everything inside the function (which should be very small) and put it in a do block, and take all the parameters that were being called, and put them at the top of the block as a localised @_ list.
Mind you, if I were that interested in speed, I'd be doing this whole thing in C or C++ anyway. Given that I'm already running perl, I'm not going to worry about the overhead of function calls. The speed benefit I, as the programmer, am getting is already huge. I'll just tell my boss he needs a faster 'puter. He'll probably save money that way anyway.
In reply to Re^2: best way to inline code? (i.e. macro)
by Tanktalus
in thread best way to inline code? (i.e. macro)
by ManFromNeptune
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |