aboutsummaryrefslogtreecommitdiff
path: root/pk/strlen.c
diff options
context:
space:
mode:
Diffstat (limited to 'pk/strlen.c')
-rw-r--r--pk/strlen.c33
1 files changed, 0 insertions, 33 deletions
diff --git a/pk/strlen.c b/pk/strlen.c
deleted file mode 100644
index 57794b7..0000000
--- a/pk/strlen.c
+++ /dev/null
@@ -1,33 +0,0 @@
-// See LICENSE for license details.
-
-#include <string.h>
-#include <limits.h>
-
-#if ULONG_MAX != 18446744073709551615UL && ULONG_MAX != 4294967295UL
-# error need sizeof(long) == 4 or sizeof(long) == 8
-#endif
-
-// from http://www-graphics.stanford.edu/~seander/bithacks.html
-static inline long hasZeroByte(long l)
-{
-#if ULONG_MAX == 4294967295UL
- return (l - 0x01010101UL) & ~l & 0x80808080UL;
-#else
- return (l - 0x0101010101010101UL) & ~l & 0x8080808080808080UL;
-#endif
-}
-
-size_t strlen(const char* s)
-{
- size_t i = 0;
-
- // use optimized version if string starts on a long boundary
- if(((long)s & (sizeof(long)-1)) == 0)
- while(!hasZeroByte(*(long*)(s+i)))
- i += sizeof(long);
-
- while(s[i])
- i++;
-
- return i;
-}