Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace home-brew string end searching with memchr.
With long aux tags the trival while loop can be suprisingly slow. "while (s < end && *s) ++s;" isn't well vectorised or turned into word-by-word processing by neither gcc nor clang, but these tricks are used by the system memchr implementation. An alternative could be this (used in my WIP VCF parser), which is more optimised for relatively short strings. Included here just for potential future reference on systems with noddy memchr implementations. #define haszero(x) (((x)-0x0101010101010101UL)&~(x)&0x8080808080808080UL) static inline char *memchr8(char *s, char sym, size_t len) { const uint64_t sym8 = sym * 0x0101010101010101UL; uint64_t *s8 = (uint64_t *)s; uint64_t *s8_end = (uint64_t *)(s+(len&~7)); while (s8 < s8_end && !haszero(*s8 ^ sym8)) s8++; // Precise identification char *s_end = s + len; s = (char *)s8; while (s < s_end && *s != sym) { s++; } return s < s_end ? s : NULL; }
- Loading branch information