Factor handbook > The implementation > Optimizing compiler > Compiler specialization hints

Next:specialized-def ( word -- quot )


Inputs and outputs
defspeca word or method
hints...a list of sequences of classes or literals

Word description
Defines specialization hints for a word or a method.

Each sequence in the list will cause a specialized version of the word to be compiled. Classes are tested for using their predicate, and literals are tested using eq?.

The append word has a specializer for the very common case where two strings or two arrays are appended:
USING: arrays hints sequences strings ; HINTS: append { string string } { array array } ;

Specializers can also be defined on methods:
USING: assocs hashtables hints kernel sequences ; GENERIC: count-occurrences ( elt obj -- n ) M: sequence count-occurrences [ = ] with count ; M: assoc count-occurrences swap [ = nip ] curry assoc-filter assoc-size ; HINTS: M\ sequence count-occurrences { object array } ; HINTS: M\ assoc count-occurrences { object hashtable } ;