3.3 Using type-specific operations

3.3.2 Increasing the efficiency of array access

You can make array and sequence operations faster by adding type declarations. To use the most efficient form of array access, you must make all of the following declarations:

If you do not specify all of the information, the Compiler cannot generate the most efficient array access code. For example, each of the following declarations allows the Compiler to generate the most efficient array access code:

;; The type simple-vector is equivalent to the type 
;; (simple-array t (*)).
(declare (type simple-vector v))

(declare (type (simple-array t (* *)) a)) (declare (type (simple-array (unsigned-byte 8) (*)) v8))

The following declarations, however, contain insufficient information:

;; The type vector does not imply the type simple-array.
(declare (type (vector (unsigned-byte 8)) v))

;; The element-type is not known. (declare (type (simple-array * (2 3)) a))

;; The number of dimensions is not specified. (declare (type (simple-array t) a1))

If all arrays in a piece of code are of a certain type, it might be simpler to use atype-reduce declaration to restrict the types of all arrays. If an application uses only simple one-, two-, or three-dimensional arrays of typet, for example, the following declaration could be used:

(declare (type-reduce (array * (*)) simple-vector)
        (type-reduce (array * (* *)) (simple-array t (* *)))
        (type-reduce (array * (* * *)) (simple-array t (* * *))))


The Advanced User's Guide - 9 SEP 1996

Generated with Harlequin WebMaker