diff options
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) | |||
43 | return (int32_t)(a->len - b->len); | 43 | return (int32_t)(a->len - b->len); |
44 | } | 44 | } |
45 | 45 | ||
46 | typedef union | ||
47 | #ifdef __GNUC__ | ||
48 | __attribute__((packed)) | ||
49 | #endif | ||
50 | Unaligned32 { uint32_t u; uint8_t b[4]; } Unaligned32; | ||
51 | |||
52 | /* Unaligned read of uint32_t. */ | ||
53 | static LJ_AINLINE uint32_t str_getu32(const void *p) | ||
54 | { | ||
55 | return ((const Unaligned32 *)p)->u; | ||
56 | } | ||
57 | |||
58 | /* Fast string data comparison. Caveat: unaligned access to 1st string! */ | 46 | /* Fast string data comparison. Caveat: unaligned access to 1st string! */ |
59 | static LJ_AINLINE int str_fastcmp(const char *a, const char *b, MSize len) | 47 | static LJ_AINLINE int str_fastcmp(const char *a, const char *b, MSize len) |
60 | { | 48 | { |
@@ -62,7 +50,7 @@ static LJ_AINLINE int str_fastcmp(const char *a, const char *b, MSize len) | |||
62 | lua_assert(len > 0); | 50 | lua_assert(len > 0); |
63 | lua_assert((((uintptr_t)a + len) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4); | 51 | lua_assert((((uintptr_t)a + len) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4); |
64 | do { /* Note: innocuous access up to end of string + 3. */ | 52 | do { /* Note: innocuous access up to end of string + 3. */ |
65 | uint32_t v = str_getu32(a+i) ^ *(const uint32_t *)(b+i); | 53 | uint32_t v = lj_getu32(a+i) ^ *(const uint32_t *)(b+i); |
66 | if (v) { | 54 | if (v) { |
67 | i -= len; | 55 | i -= len; |
68 | #if LJ_LE | 56 | #if LJ_LE |
@@ -115,11 +103,11 @@ GCstr *lj_str_new(lua_State *L, const char *str, size_t lenx) | |||
115 | g = G(L); | 103 | g = G(L); |
116 | /* Compute string hash. Constants taken from lookup3 hash by Bob Jenkins. */ | 104 | /* Compute string hash. Constants taken from lookup3 hash by Bob Jenkins. */ |
117 | if (len >= 4) { /* Caveat: unaligned access! */ | 105 | if (len >= 4) { /* Caveat: unaligned access! */ |
118 | a = str_getu32(str); | 106 | a = lj_getu32(str); |
119 | h ^= str_getu32(str+len-4); | 107 | h ^= lj_getu32(str+len-4); |
120 | b = str_getu32(str+(len>>1)-2); | 108 | b = lj_getu32(str+(len>>1)-2); |
121 | h ^= b; h -= lj_rol(b, 14); | 109 | h ^= b; h -= lj_rol(b, 14); |
122 | b += str_getu32(str+(len>>2)-1); | 110 | b += lj_getu32(str+(len>>2)-1); |
123 | } else if (len > 0) { | 111 | } else if (len > 0) { |
124 | a = *(const uint8_t *)str; | 112 | a = *(const uint8_t *)str; |
125 | h ^= *(const uint8_t *)(str+len-1); | 113 | h ^= *(const uint8_t *)(str+len-1); |