diff options
author | Joakim Tjernlund <joakim.tjernlund@transmode.se> | 2004-08-10 14:44:34 +0000 |
---|---|---|
committer | Joakim Tjernlund <joakim.tjernlund@transmode.se> | 2004-08-10 14:44:34 +0000 |
commit | 1939e0ebaf3303fc6037cea641de6e4249554d75 (patch) | |
tree | 2644e02e6425d021b641835a7c1e2ad562652037 /ldso/include/dl-string.h | |
parent | 856860ed52514d0e8052297a71fc8a345c573995 (diff) |
_dl_get_last_path_component:
handle "" strings and optimze it.
_dl_simple_ltoa,_dl_simple_ltoahex:
Optimize for archs which can do pre increment/decrement and load/store
in one instruction.
Diffstat (limited to 'ldso/include/dl-string.h')
-rw-r--r-- | ldso/include/dl-string.h | 50 |
1 files changed, 19 insertions, 31 deletions
diff --git a/ldso/include/dl-string.h b/ldso/include/dl-string.h index 648b59546..2395221ab 100644 --- a/ldso/include/dl-string.h +++ b/ldso/include/dl-string.h @@ -177,32 +177,20 @@ static inline void * _dl_memset(void * str,int c,size_t len) static inline char *_dl_get_last_path_component(char *path) { - char *s; - register char *ptr = path; - register char *prev = 0; + register char *ptr = path-1; - while (*ptr) - ptr++; - s = ptr - 1; + while (*++ptr) + ;/* empty */ /* strip trailing slashes */ - while (s != path && *s == '/') { - *s-- = '\0'; + while (ptr != path && *--ptr == '/') { + *ptr = '\0'; } /* find last component */ - ptr = path; - while (*ptr != '\0') { - if (*ptr == '/') - prev = ptr; - ptr++; - } - s = prev; - - if (s == NULL || s[1] == '\0') - return path; - else - return s+1; + while (ptr != path && *--ptr != '/') + ;/* empty */ + return ptr == path ? ptr : ptr+1; } /* Early on, we can't call printf, so use this to print out @@ -211,33 +199,33 @@ static inline char *_dl_get_last_path_component(char *path) static inline char *_dl_simple_ltoa(char * local, unsigned long i) { /* 21 digits plus null terminator, good for 64-bit or smaller ints */ - char *p = &local[21]; - *p-- = '\0'; + char *p = &local[22]; + *--p = '\0'; do { char temp; do_rem(temp, i, 10); - *p-- = '0' + temp; + *--p = '0' + temp; i /= 10; } while (i > 0); - return p + 1; + return p; } static inline char *_dl_simple_ltoahex(char * local, unsigned long i) { /* 21 digits plus null terminator, good for 64-bit or smaller ints */ - char *p = &local[21]; - *p-- = '\0'; + char *p = &local[22]; + *--p = '\0'; do { char temp = i & 0xf; if (temp <= 0x09) - *p-- = '0' + temp; + *--p = '0' + temp; else - *p-- = 'a' - 0x0a + temp; + *--p = 'a' - 0x0a + temp; i >>= 4; } while (i > 0); - *p-- = 'x'; - *p-- = '0'; - return p + 1; + *--p = 'x'; + *--p = '0'; + return p; } |