Chameleon

Chameleon Commit Details

Date:2014-01-11 21:01:20 (10 years 3 months ago)
Author:Chuck Fry
Commit:2333
Parents: 2332
Message:Optimize basic string functions strlen, strncmp, strncat, strcat
Changes:
M/branches/chucko/i386/libsa/string.c

File differences

branches/chucko/i386/libsa/string.c
110110
111111
112112
113
114
115
113
114
115
116116
117117
118118
......
138138
139139
140140
141
141
142
142143
143
144
145
146
147
144
145
146
147
148
149
150
151
152
153
148154
149155
150156
......
161167
162168
163169
164
165
170
166171
167172
168173
......
224229
225230
226231
227
228
229
232
230233
231234
232235
233236
234237
235
238
239
240
241
242
236243
237244
238245
size_t strlen(const char * s)
{
int n = 0;
while (*s++) n++;
return(n);
const char* save = s;
while (*s++);
return (--s) - save;
}
/*#endif*/
return (*s1 - *s2);
}
int strncmp(const char * s1, const char * s2, size_t len)
/* Derived from FreeBSD source */
int strncmp(const char * s1, const char * s2, size_t n)
{
register int n = len;
while (--n >= 0 && *s1 == *s2++)
if (*s1++ == '\0')
return(0);
return(n<0 ? 0 : *s1 - *--s2);
if (!n)
return 0;
do {
if (*s1 != *s2++)
return (*(const unsigned char *)s1 -
*(const unsigned char *)(s2 - 1));
if (!*s1++)
break;
} while (--n);
return 0;
}
char *
{
register char *ret = s1;
while (n && (*s1++ = *s2++))
--n;
/* while (n--) *s1++ = '\0'; */
--n;
if (n > 0) {
bzero(s1, n);
}
register char *ret = s1;
while (*s1)
s1++;
while (n-- && *s2)
*s1++ = *s2++;
*s1 = '\0';
while (n-- && (*s1++ = *s2++));
return ret;
}
char *strcat(char *s1, const char *s2)
{
return(strncat(s1, s2, strlen(s2)));
register char *ret = s1;
while (*s1)
s1++;
while ((*s1++ = *s2++));
return ret;
}
char *strdup(const char *s1)

Archive Download the corresponding diff file

Revision: 2333