speeded up a bit

This commit is contained in:
ceriel 1989-02-22 16:16:11 +00:00
parent b1626ca895
commit 5187e46404
5 changed files with 30 additions and 36 deletions

View file

@ -7,8 +7,9 @@ register char *s1, *s2;
char *original = s1; char *original = s1;
/* Find the end of s1. */ /* Find the end of s1. */
while (*s1 != 0) s1++; while (*s1++ != 0) ;
s1--;
/* Now copy s2 to the end of s1. */ /* Now copy s2 to the end of s1. */
while (*s1++ = *s2++) /* nothing */ ; while (*s1++ = *s2++) /* nothing */ ;
return(original); return(original);

View file

@ -1,16 +1,10 @@
/* $Header$ */ /* $Header$ */
int strcmp(s1, s2) int
register char *s1, *s2; strcmp(s, t)
register char *s, *t;
{ {
/* Compare 2 strings. */ while (*s == *t++)
if (*s++ == '\0')
for(;;) { return 0;
if (*s1 != *s2) { return *s - *--t;
if (!*s1) return -1;
if (!*s2) return 1;
return(*s1 - *s2);
}
if (*s1++ == 0) return(0);
s2++;
}
} }

View file

@ -1,11 +1,11 @@
/* $Header$ */ /* $Header$ */
int strlen(s) int
char *s; strlen(s)
char *s;
{ {
/* Return length of s. */ register char *b = s;
char *original = s; while (*b++)
;
while (*s != 0) s++; return b - s - 1;
return(s - original);
} }

View file

@ -10,7 +10,9 @@ int n;
if (n <= 0) return(s1); if (n <= 0) return(s1);
/* Find the end of s1. */ /* Find the end of s1. */
while (*s1 != 0) s1++; while (*s1++ != 0) ;
s1--;
/* Now copy s2 to the end of s1. */ /* Now copy s2 to the end of s1. */
while (*s1++ = *s2++) { while (*s1++ = *s2++) {

View file

@ -1,19 +1,16 @@
/* $Header$ */ /* $Header$ */
int int
strncmp(s1, s2, n) strncmp(s, t, n)
register char *s1, *s2; register char *s, *t;
int n; register int n;
{ {
/* Compare two strings, but at most n characters. */ while (n-- > 0) {
if (*s == *t++) {
while (n-- > 0) { if (*s++ == '\0')
if (*s1 != *s2) { return 0;
if (!*s1) return -1; }
if (!*s2) return 1; else
return(*s1 - *s2); return *s - *--t;
} }
if (*s1++ == 0) break; return 0;
s2++;
}
return 0;
} }