summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2024-06-13 17:59:40 -0400
committerAlan Wu <XrXr@users.noreply.github.com>2024-06-13 18:52:09 -0400
commit6416ee33ebfe649e7e224f6ad5f80c40b128cce6 (patch)
tree1811125081b6c5d0f503152bbb68f702fe86aff3
parenta8730adb600cba9b2933f2d0d1c3716a9cbe8c76 (diff)
Simplify unaligned write for pre-computed string hash
-rw-r--r--string.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/string.c b/string.c
index ab26037262..59ddb6e741 100644
--- a/string.c
+++ b/string.c
@@ -376,9 +376,8 @@ str_precompute_hash(VALUE str)
RUBY_ASSERT(free_bytes >= sizeof(st_index_t));
#endif
- typedef struct {char bytes[sizeof(st_index_t)];} unaligned_index;
- union {st_index_t i; unaligned_index b;} u = {.i = str_do_hash(str)};
- *(unaligned_index *)(RSTRING_END(str) + TERM_LEN(str)) = u.b;
+ st_index_t hash = str_do_hash(str);
+ memcpy(RSTRING_END(str) + TERM_LEN(str), &hash, sizeof(hash));
FL_SET(str, STR_PRECOMPUTED_HASH);