speeded up a bit
This commit is contained in:
parent
b1626ca895
commit
5187e46404
5 changed files with 30 additions and 36 deletions
|
@ -7,8 +7,9 @@ register char *s1, *s2;
|
|||
char *original = s1;
|
||||
|
||||
/* Find the end of s1. */
|
||||
while (*s1 != 0) s1++;
|
||||
while (*s1++ != 0) ;
|
||||
|
||||
s1--;
|
||||
/* Now copy s2 to the end of s1. */
|
||||
while (*s1++ = *s2++) /* nothing */ ;
|
||||
return(original);
|
||||
|
|
|
@ -1,16 +1,10 @@
|
|||
/* $Header$ */
|
||||
int strcmp(s1, s2)
|
||||
register char *s1, *s2;
|
||||
int
|
||||
strcmp(s, t)
|
||||
register char *s, *t;
|
||||
{
|
||||
/* Compare 2 strings. */
|
||||
|
||||
for(;;) {
|
||||
if (*s1 != *s2) {
|
||||
if (!*s1) return -1;
|
||||
if (!*s2) return 1;
|
||||
return(*s1 - *s2);
|
||||
}
|
||||
if (*s1++ == 0) return(0);
|
||||
s2++;
|
||||
}
|
||||
while (*s == *t++)
|
||||
if (*s++ == '\0')
|
||||
return 0;
|
||||
return *s - *--t;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/* $Header$ */
|
||||
int strlen(s)
|
||||
char *s;
|
||||
int
|
||||
strlen(s)
|
||||
char *s;
|
||||
{
|
||||
/* Return length of s. */
|
||||
register char *b = s;
|
||||
|
||||
char *original = s;
|
||||
|
||||
while (*s != 0) s++;
|
||||
return(s - original);
|
||||
while (*b++)
|
||||
;
|
||||
return b - s - 1;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,9 @@ int n;
|
|||
if (n <= 0) return(s1);
|
||||
|
||||
/* Find the end of s1. */
|
||||
while (*s1 != 0) s1++;
|
||||
while (*s1++ != 0) ;
|
||||
|
||||
s1--;
|
||||
|
||||
/* Now copy s2 to the end of s1. */
|
||||
while (*s1++ = *s2++) {
|
||||
|
|
|
@ -1,19 +1,16 @@
|
|||
/* $Header$ */
|
||||
int
|
||||
strncmp(s1, s2, n)
|
||||
register char *s1, *s2;
|
||||
int n;
|
||||
strncmp(s, t, n)
|
||||
register char *s, *t;
|
||||
register int n;
|
||||
{
|
||||
/* Compare two strings, but at most n characters. */
|
||||
|
||||
while (n-- > 0) {
|
||||
if (*s1 != *s2) {
|
||||
if (!*s1) return -1;
|
||||
if (!*s2) return 1;
|
||||
return(*s1 - *s2);
|
||||
if (*s == *t++) {
|
||||
if (*s++ == '\0')
|
||||
return 0;
|
||||
}
|
||||
if (*s1++ == 0) break;
|
||||
s2++;
|
||||
else
|
||||
return *s - *--t;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue