From: padre@elte.hu Date: Fri, 19 Mar 2004 14:56:09 +0000 (+0000) Subject: Clarifications on constants subroutines, based on: X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=882672714c7b1c946ae8e88a96766a508485d95e;p=p5sagit%2Fp5-mst-13.2.git Clarifications on constants subroutines, based on: Subject: [perl #27768] [patch] wrong examples in perlsub/"Constant Functions" From: "padre@elte.hu (via RT)" Message-ID: p4raw-id: //depot/perl@22557 --- diff --git a/pod/perlsub.pod b/pod/perlsub.pod index e830130..3619014 100644 --- a/pod/perlsub.pod +++ b/pod/perlsub.pod @@ -1133,7 +1133,17 @@ The following functions would all be inlined: sub FLAG_MASK () { FLAG_FOO | FLAG_BAR } sub OPT_BAZ () { not (0x1B58 & FLAG_MASK) } - sub BAZ_VAL () { + + sub N () { int(OPT_BAZ) / 3 } + + sub FOO_SET () { 1 if FLAG_MASK & FLAG_FOO } + +Be aware that these will not be inlined; as they contain inner scopes, +the constant folding doesn't reduce them to a single constant: + + sub foo_set () { if (FLAG_MASK & FLAG_FOO) { 1 } } + + sub baz_val () { if (OPT_BAZ) { return 23; } @@ -1142,13 +1152,6 @@ The following functions would all be inlined: } } - sub N () { int(BAZ_VAL) / 3 } - BEGIN { - my $prod = 1; - for (1..N) { $prod *= $_ } - sub N_FACTORIAL () { $prod } - } - If you redefine a subroutine that was eligible for inlining, you'll get a mandatory warning. (You can use this warning to tell whether or not a particular subroutine is considered constant.) The warning is