From 068b12adfb4577b8e732f56e979017cd690baec5 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 9 Oct 2019 21:36:39 -0500 Subject: 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. --- lib/lib.c | 6 +++--- 1 file 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; -- cgit v1.2.3