The switch is uniquely qualified to implement a duff device.

\tsend(to, from, count)
\tregister short *to, *from;
\tregister count;
\t{
\t\tregister n=(count+7)/8;
\t\tswitch(count%8){
\t\tcase 0:\tdo{\t*to = *from++;
\t\tcase 7:\t\t*to = *from++;
\t\tcase 6:\t\t*to = *from++;
\t\tcase 5:\t\t*to = *from++;
\t\tcase 4:\t\t*to = *from++;
\t\tcase 3:\t\t*to = *from++;
\t\tcase 2:\t\t*to = *from++;
\t\tcase 1:\t\t*to = *from++;
\t\t\t}while(--n>0);
\t\t}
\t}

Apologies for the K&R but this is the exact code from Tom Duff's usenet posting. This sick and wrong hack gives partial loop unrolling when doing data moving. You can't exactly do this with if else's. Oh for the days when men were men and compilers were compilers and it was you against the awesomely slow machine struggling to coax behavior that was just barely good enough.

OK, whatever.

For completeness I thought I'd toss in the Squeak implementation of caseOf: otherwise:

A search of the stock images reveals that it is used just 3 times - two of those are in the parser.


someObject caseOf: {
[someExpression]->[someCodeToPerform].
[otherExpression]=>[otherThingToDo]. }
otherwise: [do this].


which is in fact implemented as:

caseOf: aBlockAssociationCollection otherwise: aBlock

aBlockAssociationCollection associationsDo:
[:assoc | (assoc key value = self) ifTrue: [^assoc value value]].
\t^ aBlock value