diff options
author | Mike Pall <mike> | 2011-05-09 18:09:29 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2011-05-09 18:09:29 +0200 |
commit | 28e87d33e931661e8118a25b293213938a9e0af4 (patch) | |
tree | 8177a3e7d463ed27bbb0e63f7a12a060d836029b /src/lj_str.c | |
parent | d9c1f771a7575510a9612e0a67be6c61d83de982 (diff) | |
download | luajit2-28e87d33e931661e8118a25b293213938a9e0af4.tar.gz |
Use common helper functions for unaligned loads.
Diffstat (limited to 'src/lj_str.c')
-rw-r--r-- | src/lj_str.c | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/src/lj_str.c b/src/lj_str.c index 2b94d977..516acefe 100644 --- a/src/lj_str.c +++ b/src/lj_str.c @@ -43,18 +43,6 @@ int32_t LJ_FASTCALL lj_str_cmp(GCstr *a, GCstr *b) return (int32_t)(a->len - b->len); } -typedef union -#ifdef __GNUC__ -__attribute__((packed)) -#endif -Unaligned32 { uint32_t u; uint8_t b[4]; } Unaligned32; - -/* Unaligned read of uint32_t. */ -static LJ_AINLINE uint32_t str_getu32(const void *p) -{ - return ((const Unaligned32 *)p)->u; -} - /* Fast string data comparison. Caveat: unaligned access to 1st string! */ static LJ_AINLINE int str_fastcmp(const char *a, const char *b, MSize len) { @@ -62,7 +50,7 @@ static LJ_AINLINE int str_fastcmp(const char *a, const char *b, MSize len) lua_assert(len > 0); lua_assert((((uintptr_t)a + len) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4); do { /* Note: innocuous access up to end of string + 3. */ - uint32_t v = str_getu32(a+i) ^ *(const uint32_t *)(b+i); + uint32_t v = lj_getu32(a+i) ^ *(const uint32_t *)(b+i); if (v) { i -= len; #if LJ_LE @@ -115,11 +103,11 @@ GCstr *lj_str_new(lua_State *L, const char *str, size_t lenx) g = G(L); /* Compute string hash. Constants taken from lookup3 hash by Bob Jenkins. */ if (len >= 4) { /* Caveat: unaligned access! */ - a = str_getu32(str); - h ^= str_getu32(str+len-4); - b = str_getu32(str+(len>>1)-2); + a = lj_getu32(str); + h ^= lj_getu32(str+len-4); + b = lj_getu32(str+(len>>1)-2); h ^= b; h -= lj_rol(b, 14); - b += str_getu32(str+(len>>2)-1); + b += lj_getu32(str+(len>>2)-1); } else if (len > 0) { a = *(const uint8_t *)str; h ^= *(const uint8_t *)(str+len-1); |