3.2 Making declarations
inlinedeclaration asks the Compiler to replace the procedure call to a function with the machine-language code for that function. Using the machine-language code for a function is called in-line coding or open coding.
Using in-line code eliminates some of the run-time overhead in calling functions. In-line coding is especially useful for simple functions; it is not as useful for large functions where the time needed to call the function is small compared to the execution time of the function. In-line coding should be used selectively because it usually increases the size of compiled code.
notinline declaration tells the Compiler not to use in-line code for a function, even for a function it would normally code in line. If a function is declared
notinline, a call to the function replaces the in-line code.
Notinline declarations can be useful when you are debugging code. The Compiler can choose to ignore an
inline declaration; it must obey a
Local functions that have been defined by using the
flet or the
labels special form can be declared
inline with an
inline declaration, as shown in the following example:
;;; Compute the distance between two 2-dimensional points. (defun distance-2d (p1 p2) (flet ((square (x) (* x x))) (declare (inline square)) (flet ((square-d (x1 x2) (square (- x2 x1)))) (declare (inline square-d)) (sqrt (+ (square-d (point-x p1) (point-x p2)) (square-d (point-y p1) (point-y p2)))))))To declare top-level functions, use an
inlineproclamation. The proclamation must precede the definition of the proclaimed function, as shown in the following example:
(proclaim '(inline square)) (defun square (x) (* x x))You can also use the function
defsubstto simultaneously define a function and declare it
inline. The following expression produces the same result as the proclamation and definition in the preceding example:
(defsubst square (x) (* x x))Unless
notinlinedeclarations are used, the Compiler automatically generates in-line code for many system-provided functions, such as
cdr. The Compiler normally codes the following functions in line:
inlinecan also increase code size. In particular, all the
make-<foo>functions are automatically inlined, so in the case of constructors with large number of slots, compilation can dramatically increase the size of the code. This is usually not a problem, as most structures are small, and hence the constructors are small also. If your code contains large constructors, you can save space by proclaiming or declaring the constructor
notinlineto keep it from being expanded inline.
Generated with Harlequin WebMaker