Tricky way to unroll string copy loops

Gary M. Samuelson garys at bunker.UUCP
Wed Apr 10 05:06:54 AEST 1985


I would like to suggest one aesthetic improvement to
Duff's Device.  It would look slightly less revolting
(in my opinion) if all of the case labels were at the
same block level:

Original:
> 			case 0: do {	*to++ = *from++;
> 			case 7:		*to++ = *from++;
>			...
> 			case 1:		*to++ = *from++;
> 				} while (--n > 0);

With my proposed change:
> 				do {
> 			case 0: 	*to++ = *from++;
> 			case 7:		*to++ = *from++;
>			...
> 			case 1:		*to++ = *from++;
> 				} while (--n > 0);

As I said, it's an aesthetic change, but then again, there
might be a case where some compiler does something with
either the 'do' or the brace which makes a difference.

I'm not sure I would use it either way.

Gary Samuelson
ittvax!bunker!garys



More information about the Comp.lang.c mailing list