Simplify unaligned write for pre-computed string hash
This commit is contained in:
parent
a8730adb60
commit
6416ee33eb
5
string.c
5
string.c
@ -376,9 +376,8 @@ str_precompute_hash(VALUE str)
|
|||||||
RUBY_ASSERT(free_bytes >= sizeof(st_index_t));
|
RUBY_ASSERT(free_bytes >= sizeof(st_index_t));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct {char bytes[sizeof(st_index_t)];} unaligned_index;
|
st_index_t hash = str_do_hash(str);
|
||||||
union {st_index_t i; unaligned_index b;} u = {.i = str_do_hash(str)};
|
memcpy(RSTRING_END(str) + TERM_LEN(str), &hash, sizeof(hash));
|
||||||
*(unaligned_index *)(RSTRING_END(str) + TERM_LEN(str)) = u.b;
|
|
||||||
|
|
||||||
FL_SET(str, STR_PRECOMPUTED_HASH);
|
FL_SET(str, STR_PRECOMPUTED_HASH);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user