aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2019-10-09 21:36:39 -0500
committerRob Landley <rob@landley.net>2019-10-09 21:36:39 -0500
commit068b12adfb4577b8e732f56e979017cd690baec5 (patch)
treee66af09ccf7dd44b14e84e51e582b8b40f59d248 /lib
parent48d750ca5be4db45a3f04956a9d8ca87ddc45db2 (diff)
downloadtoybox-068b12adfb4577b8e732f56e979017cd690baec5.tar.gz
Don't strlen() potentially long target string each call to strstart().
The downside is we don't use assembly optimized libc comparison functions, but the common case is short/no matches until full match. Probably net win.
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/lib.c b/lib/lib.c
index cfb71ed3..dafd514a 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -447,11 +447,11 @@ char *strend(char *str, char *suffix)
// If *a starts with b, advance *a past it and return 1, else return 0;
int strstart(char **a, char *b)
{
- int len = strlen(b), i = !strncmp(*a, b, len);
+ char *c = *a;
- if (i) *a += len;
+ if (*b) while (*b++ == *c++) if (!*b) return c-*a;
- return i;
+ return 0;
}
// If *a starts with b, advance *a past it and return 1, else return 0;