From d2b8aff9b799a2402e7f7769bdfa511cc246768b Mon Sep 17 00:00:00 2001 From: Jonas Wagner Date: Wed, 20 Feb 2013 18:50:01 +0100 Subject: [PATCH] strlen: use bitwise AND for alignment test, instead of %. --- src/string/strlen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/string/strlen.c b/src/string/strlen.c index d6f8631..92784ea 100644 --- a/src/string/strlen.c +++ b/src/string/strlen.c @@ -3,7 +3,7 @@ #include #include -#define ALIGN (sizeof(size_t)) +#define ALIGN (sizeof(size_t)-1) #define ONES ((size_t)-1/UCHAR_MAX) #define HIGHS (ONES * (UCHAR_MAX/2+1)) #define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) @@ -12,7 +12,7 @@ size_t strlen(const char *s) { const char *a = s; const size_t *w; - for (; (uintptr_t)s % ALIGN; s++) if (!*s) return s-a; + for (; (uintptr_t)s & ALIGN; s++) if (!*s) return s-a; for (w = (const void *)s; !HASZERO(*w); w++); for (s = (const void *)w; *s; s++); return s-a; -- 1.7.10.4