in reply to Re^2: Slow constants
in thread Slow constants

Doesn't the absence of an empty prototype in the assignment *$AUTOLOAD = sub { $val } mean that these are just normal (non-constant) subs, and will therefore never be inlined, and therefore, called everytime they are used?

## From Socket.pm (Fnctl.pm contains an nearly identical sub) sub AUTOLOAD { my($constname); ($constname = $AUTOLOAD) =~ s/.*:://; croak "&Socket::constant not defined" if $constname eq 'constant'; my ($error, $val) = constant($constname); if ($error) { croak $error; } *$AUTOLOAD = sub { $val }; goto &$AUTOLOAD; }

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^4: Slow constants
by Perl Mouse (Chaplain) on Nov 02, 2005 at 17:22 UTC
    Doesn't the absence of an empty prototype in the assignment *$AUTOLOAD = sub { $val } mean that these are just normal (non-constant) subs, and will therefore never be inlined, and therefore, called everytime they are used?
    Eh, yes. And no. They will indeed by called everytime they are used - just as I said: The second time, the sub is there and the sub is called. (But a subsequent call to the same constant will not invoke AUTOLOAD again). However, it does not matter whether there's a prototype present or not - the calling code is already compiled, so it's too late for inlining. Although it might matter if there's future code to be string-evalled that uses a previous called constant.
    Perl --((8:>*