Misc. doc patches missing in _20
[p5sagit/p5-mst-13.2.git] / pod / perlsub.pod
index 6bd3fe8..2d3e666 100644 (file)
@@ -754,6 +754,47 @@ starts scribbling on your @_ parameter list.
 This is all very powerful, of course, and should be used only in moderation
 to make the world a better place.  
 
+=head2 Constant Functions
+
+Functions with a prototype of C<()> are potential candidates for
+inlining.  If the result after optimization and constant folding is a
+constant then it will be used in place of calls to the function.
+
+All of the following functions would be inlined.
+
+    sub PI ()          { 3.14159 }
+    sub ST_DEV ()      { 0 }
+    sub ST_INO ()      { 1 }
+
+    sub FLAG_FOO ()    { 1 << 8 }
+    sub FLAG_BAR ()    { 1 << 9 }
+    sub FLAG_MASK ()   { FLAG_FOO | FLAG_BAR }
+    
+    sub OPT_BAZ ()     { 1 }
+    sub BAZ_VAL () {
+       if (OPT_BAZ) {
+           return 23;
+       }
+       else {
+           return 42;
+       }
+    }
+
+If you redefine a subroutine which 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
+considered severe enough not to be optional because previously compiled
+invocations of the function will still be using the old value of the
+function.  If you need to be able to redefine the subroutine you need to
+ensure that it isn't inlined, either by dropping the C<()> prototype
+(which changes the calling semantics, so beware) or by thwarting the
+inlining mechanism in some other way, such as
+
+    my $dummy;
+    sub not_inlined () {
+       $dummy || 23
+    }
+
 =head2 Overriding Builtin Functions
 
 Many builtin functions may be overridden, though this should be tried