[PATCH] smaller strlen()

From: Alexey Dobriyan
Date: Fri Aug 26 2016 - 16:01:29 EST


gcc prefers "*s++" style code for some reason, doesn't unroll loop
condition check once. Kernel strings are small but they aren't of 0
length, so that additional branch was almost never taken.

$ ./scripts/bloat-o-meter ../vmlinux-000 ../obj/vmlinux
strlen 30 26 -4
strlcpy 71 64 -7
strlcat 120 99 -21

strlcpy() and strlcat() are collateral damage :^)

Signed-off-by: Alexey Dobriyan <adobriyan@xxxxxxxxx>
---

lib/string.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

--- a/lib/string.c
+++ b/lib/string.c
@@ -476,11 +476,11 @@ EXPORT_SYMBOL(strim);
*/
size_t strlen(const char *s)
{
- const char *sc;
+ const char *s0 = s;

- for (sc = s; *sc != '\0'; ++sc)
+ while (*s++)
/* nothing */;
- return sc - s;
+ return s - s0 - 1;
}
EXPORT_SYMBOL(strlen);
#endif