in reply to Re: is use strict a compile time directive?
in thread is use strict a compile time directive?
Avoiding strict refs for speed? Ack! Pttht!
A quick walk thorugh the source reveals that way down in the bowels of op.c, Perl_ck_rvconst is the function checking strict 'refs'. The section reads:
So we've got a a bitwise AND (and a pointer deref) going on to see if we've got something that might throw a stricture error. If there's no strict, we skip this next part.if ((PL_hints & HINT_STRICT_REFS)&&(kid->op_private & OPpCONST_BARE)){ char *badthing = Nullch; switch (o->op_type) { case OP_RV2SV: badthing = "a SCALAR"; break; case OP_RV2AV: badthing = "an ARRAY"; break; case OP_RV2HV: badthing = "a HASH"; break; } if (badthing) Perl_croak(aTHX_ "Can't use bareword (\"%s\") as %s ref while \"strict refs\" + in use", name, badthing); }
Next, we've got a switch statement with three possibilities: we wanted a SCALAR, ARRAY or HASH reference. That'll compile down to something tight and small (three comparisons, a jump-table of some kind, etc...). Only if any of these match does badthing get set and the error thrown.
So at the very worst case that doesn't actually throw an error you've got:
So if you're worried about a small number of ANDs, pointer moving and comparisons to check for strict because you're looking for speed: look elsewhere. There's nothing to optimize here.
|
|---|