diff options
author | Jeremy Allison <jra@samba.org> | 1998-09-15 01:38:10 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 1998-09-15 01:38:10 +0000 |
commit | ffa450acddb7aec6a440ae3fe6032c109805d176 (patch) | |
tree | b8ec5baf4ecae6283685c23079e5a310d52d6a9a | |
parent | 4a62b73633b8f8707a2961b355d4997f429c86bc (diff) | |
download | samba-ffa450acddb7aec6a440ae3fe6032c109805d176.tar.gz |
Removed hideous inefficiencies in old trim_string code. This was making
calls to strlen() a profiling hotspot.
Jeremy.
-rw-r--r-- | source/lib/util.c | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/source/lib/util.c b/source/lib/util.c index 668857f004e..002b31d027d 100644 --- a/source/lib/util.c +++ b/source/lib/util.c @@ -1089,23 +1089,30 @@ trim the specified elements off the front and back of a string BOOL trim_string(char *s,char *front,char *back) { BOOL ret = False; - while (front && *front && strncmp(s,front,strlen(front)) == 0) - { - char *p = s; - ret = True; - while (1) - { - if (!(*p = p[strlen(front)])) - break; - p++; - } - } - while (back && *back && strlen(s) >= strlen(back) && - (strncmp(s+strlen(s)-strlen(back),back,strlen(back))==0)) + int front_len = (front && *front) ? strlen(front) : 0; + int back_len = (back && *back) ? strlen(back) : 0; + int s_len; + + while (front_len && strncmp(s, front, front_len) == 0) + { + char *p = s; + ret = True; + while (1) { - ret = True; - s[strlen(s)-strlen(back)] = 0; + if (!(*p = p[front_len])) + break; + p++; } + } + + s_len = strlen(s); + while (back_len && s_len >= back_len && + (strncmp(s + s_len - back_len, back, back_len)==0)) + { + ret = True; + s[s_len - back_len] = 0; + s_len = strlen(s); + } return(ret); } |