4 ms·
That snippet appears to be out of date. Version 0.8.34 does something similar to what you suggest. #define ngx_str3Ocmp(m, c0, c1, c2, c3)
by jared314 17y ago
That snippet appears to be out of date. Version 0.8.34 does something similar to what you suggest.
#define ngx_str3Ocmp(m, c0, c1, c2, c3) \
*(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0)
- yosh 17y agoCareful with casting strings to ints like that, it'll break on architectures that require aligned accesses, i.e. if you try to load a uint32, the address of the memory location must be a multiple of 4. x86 happens to be fine with non-aligned access, but many other architectures aren't. If you look at the nginx source, that #define is guarded under NGX_HAVE_NONALIGNED and there is a fallback that does straight byte by byte comparison.
- viraptor 17y ago> fallback that does straight byte by byte comparison That's not even funny anymore... I wonder how many iterations will it take, until they discover that strncmp compiles down to "repz cmpsb" (or equivalent) and you really cannot do better than that with if-s on each character.
- oldgregg 17y agoI like to think I'm a decent programmer. Then I read threads like this. :o) Keep learning...