Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1470977
| From | Alexey Dobriyan <adobriyan@gmail.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH] smaller strlen() |
| Date | 2016-08-26 22:10 +0200 |
| Message-ID | <savBU-3hs-9@gated-at.bofh.it> (permalink) |
| Organization | linux.* mail to news gateway |
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@gmail.com>
---
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
Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread
[PATCH] smaller strlen() Alexey Dobriyan <adobriyan@gmail.com> - 2016-08-26 22:10 +0200 Re: [PATCH] smaller strlen() Joe Perches <joe@perches.com> - 2016-08-27 00:30 +0200
csiph-web