mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Simplify unaligned write for pre-computed string hash
This commit is contained in:
parent
a8730adb60
commit
6416ee33eb
1 changed files with 2 additions and 3 deletions
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…
Add table
Add a link
Reference in a new issue