summaryrefslogtreecommitdiff
path: root/ldso
diff options
context:
space:
mode:
authorJoakim Tjernlund <joakim.tjernlund@transmode.se>2004-08-10 15:06:30 +0000
committerJoakim Tjernlund <joakim.tjernlund@transmode.se>2004-08-10 15:06:30 +0000
commit635d4566d0bc6e35a9f39479076b2ccf8858a447 (patch)
tree10006dd67123c7287f5f85ace7d09fa91b091999 /ldso
parent1939e0ebaf3303fc6037cea641de6e4249554d75 (diff)
_dl_strlen,_dl_strcat,_dl_strcpy,_dl_strcmp,_dl_strncmp,
_dl_strchr,_dl_strrchr,_dl_strstr,_dl_memcmp: Optimize for archs which can do pre increment/decrement and load/store in one instruction.
Diffstat (limited to 'ldso')
-rw-r--r--ldso/include/dl-string.h64
1 files changed, 28 insertions, 36 deletions
diff --git a/ldso/include/dl-string.h b/ldso/include/dl-string.h
index 2395221ab..0b313e73f 100644
--- a/ldso/include/dl-string.h
+++ b/ldso/include/dl-string.h
@@ -24,45 +24,42 @@ static char *_dl_simple_ltoahex(char * local, unsigned long i);
static inline size_t _dl_strlen(const char * str)
{
- register char *ptr = (char *) str;
+ register const char *ptr = (char *) str-1;
- while (*ptr)
- ptr++;
+ while (*++ptr);
return (ptr - str);
}
static inline char *_dl_strcat(char *dst, const char *src)
{
- register char *ptr = dst;
-
- while (*ptr)
- ptr++;
-
- while (*src)
- *ptr++ = *src++;
- *ptr = '\0';
+ register char *ptr = dst-1;
+ src--;
+ while (*++ptr)
+ ;/* empty */
+ ptr--;
+ while ((*++ptr = *++src) != 0)
+ ;/* empty */
return dst;
}
static inline char * _dl_strcpy(char * dst,const char *src)
{
register char *ptr = dst;
-
- while (*src)
- *dst++ = *src++;
- *dst = '\0';
-
+
+ dst--;src--;
+ while ((*++dst = *++src) != 0);
+
return ptr;
}
static inline int _dl_strcmp(const char * s1,const char * s2)
{
register unsigned char c1, c2;
-
+ s1--;s2--;
do {
- c1 = (unsigned char) *s1++;
- c2 = (unsigned char) *s2++;
+ c1 = (unsigned char) *++s1;
+ c2 = (unsigned char) *++s2;
if (c1 == '\0')
return c1 - c2;
}
@@ -76,25 +73,24 @@ static inline int _dl_strncmp(const char * s1,const char * s2,size_t len)
register unsigned char c1 = '\0';
register unsigned char c2 = '\0';
+ s1--;s2--;
while (len > 0) {
- c1 = (unsigned char) *s1++;
- c2 = (unsigned char) *s2++;
+ c1 = (unsigned char) *++s1;
+ c2 = (unsigned char) *++s2;
if (c1 == '\0' || c1 != c2)
return c1 - c2;
len--;
}
-
return c1 - c2;
}
static inline char * _dl_strchr(const char * str,int c)
{
register char ch;
-
+ str--;
do {
- if ((ch = *str) == c)
+ if ((ch = *++str) == c)
return (char *) str;
- str++;
}
while (ch);
@@ -104,19 +100,17 @@ static inline char * _dl_strchr(const char * str,int c)
static inline char *_dl_strrchr(const char *str, int c)
{
register char *prev = 0;
- register char *ptr = (char *) str;
+ register char *ptr = (char *) str-1;
- while (*ptr != '\0') {
+ while (*++ptr != '\0') {
if (*ptr == c)
prev = ptr;
- ptr++;
}
if (c == '\0')
return(ptr);
return(prev);
}
-
static inline char *_dl_strstr(const char *s1, const char *s2)
{
register const char *s = s1;
@@ -150,17 +144,15 @@ static inline void * _dl_memcpy(void * dst, const void * src, size_t len)
return dst;
}
-
static inline int _dl_memcmp(const void * s1,const void * s2,size_t len)
{
- unsigned char *c1 = (unsigned char *)s1;
- unsigned char *c2 = (unsigned char *)s2;
+ unsigned char *c1 = (unsigned char *)s1-1;
+ unsigned char *c2 = (unsigned char *)s2-1;
- while (len--) {
- if (*c1 != *c2)
+ while (len) {
+ if (*++c1 != *++c2)
return *c1 - *c2;
- c1++;
- c2++;
+ len--;
}
return 0;
}