summaryrefslogtreecommitdiff
path: root/pod/perlsub.pod
diff options
context:
space:
mode:
authorpadre@elte.hu <padre@elte.hu>2004-03-19 14:56:09 +0000
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2004-03-22 20:46:52 +0000
commit882672714c7b1c946ae8e88a96766a508485d95e (patch)
treeeba1b47908cb831874d33ad619b26adfad178b3a /pod/perlsub.pod
parent2b1846f42207c006f0202b15d58a3d49680ec8e0 (diff)
downloadperl-882672714c7b1c946ae8e88a96766a508485d95e.tar.gz
Clarifications on constants subroutines, based on:
Subject: [perl #27768] [patch] wrong examples in perlsub/"Constant Functions" From: "padre@elte.hu (via RT)" <perlbug-followup@perl.org> Message-ID: <rt-3.0.8-27768-82310.5.12766475665209@perl.org> p4raw-id: //depot/perl@22557
Diffstat (limited to 'pod/perlsub.pod')
-rw-r--r--pod/perlsub.pod19
1 files changed, 11 insertions, 8 deletions
diff --git a/pod/perlsub.pod b/pod/perlsub.pod
index e830130a55..3619014e66 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