- Convert the function definition to declare its arguments

in the ANSI-C format.
 - Change the code a bit to hopefully save some cycles.
   I.e. (simplified) change

     a = b + 1;
     while (--b & 0x7)
	/* ... */
   to
     a = b;
     for (; b & 0x7; b--)
	/* ... */
   and
     while (--a >= 0)
	/* ... */
   to
     for (; a > 0; a--)
	/* ... */
 - Equip two function arguments of swab() with the 'restrict'
   type qualifier in form of the '__restrict' macro.  This is
   specified by POSIX.1-2001.
This commit is contained in:
Robert Drehmel 2002-08-30 20:33:05 +00:00
parent 8e52da4dfc
commit c9ab23eea5

View File

@ -43,24 +43,20 @@ __FBSDID("$FreeBSD$");
#include <string.h>
void
swab(from, to, len)
const void *from;
void *to;
size_t len;
swab(const void * __restrict from, void * __restrict to, size_t len)
{
unsigned long temp;
int n;
char *fp, *tp;
n = (len >> 1) + 1;
n = len >> 1;
fp = (char *)from;
tp = (char *)to;
#define STEP temp = *fp++,*tp++ = *fp++,*tp++ = temp
/* round to multiple of 8 */
while ((--n) & 07)
for (; n & 0x7; --n)
STEP;
n >>= 3;
while (--n >= 0) {
for (n >>= 3; n > 0; --n) {
STEP; STEP; STEP; STEP;
STEP; STEP; STEP; STEP;
}