summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>1998-09-15 01:38:10 +0000
committerJeremy Allison <jra@samba.org>1998-09-15 01:38:10 +0000
commit20d3988e06c0b8eab7a63ece62c538e8eeee130e (patch)
tree2d2dfa5aea99ce59481f7841e7b50611ff517c27 /source3/lib
parentcabc8f6d3192a4d3e23234948419fc9c1d11b5fd (diff)
downloadsamba-20d3988e06c0b8eab7a63ece62c538e8eeee130e.tar.gz
samba-20d3988e06c0b8eab7a63ece62c538e8eeee130e.tar.bz2
samba-20d3988e06c0b8eab7a63ece62c538e8eeee130e.zip
Removed hideous inefficiencies in old trim_string code. This was making
calls to strlen() a profiling hotspot. Jeremy. (This used to be commit ffa450acddb7aec6a440ae3fe6032c109805d176)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/util.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 668857f004..002b31d027 100644
--- a/source3/lib/util.c
+++ b/source3/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);
}