diff options
author | Rob Landley <rob@landley.net> | 2019-10-09 21:36:39 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-10-09 21:36:39 -0500 |
commit | 068b12adfb4577b8e732f56e979017cd690baec5 (patch) | |
tree | e66af09ccf7dd44b14e84e51e582b8b40f59d248 /lib | |
parent | 48d750ca5be4db45a3f04956a9d8ca87ddc45db2 (diff) | |
download | toybox-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.c | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -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; |