diff options
author | Peter Zhu <[email protected]> | 2024-08-19 11:50:21 -0400 |
---|---|---|
committer | Peter Zhu <[email protected]> | 2024-08-22 10:01:55 -0400 |
commit | 9a9e74389c08e8cb4421da88eae26c28f50e7820 (patch) | |
tree | 1ff41ef2b251ac466b1fbf6e5d2495fb6fa1e236 /weakmap.c | |
parent | 2569413b1cb9765d0e31fc8dcf0e674d428bb4e7 (diff) |
Add struct weakmap_entry for WeakMap entries
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/11421
Diffstat (limited to 'weakmap.c')
-rw-r--r-- | weakmap.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -29,6 +29,11 @@ struct weakmap { st_table *table; }; +struct weakmap_entry { + VALUE key; + VALUE val; +}; + static bool wmap_live_p(VALUE obj) { @@ -42,7 +47,7 @@ wmap_free_entry(VALUE *key, VALUE *val) /* We only need to free key because val is allocated beside key on in the * same malloc call. */ - ruby_sized_xfree(key, sizeof(VALUE) * 2); + ruby_sized_xfree(key, sizeof(struct weakmap_entry)); } static int @@ -418,10 +423,10 @@ wmap_aset_replace(st_data_t *key, st_data_t *val, st_data_t new_key_ptr, int exi RUBY_ASSERT(*(VALUE *)*key == new_key); } else { - VALUE *pair = xmalloc(sizeof(VALUE) * 2); + struct weakmap_entry *entry = xmalloc(sizeof(struct weakmap_entry)); - *key = (st_data_t)pair; - *val = (st_data_t)(pair + 1); + *key = (st_data_t)&entry->key;; + *val = (st_data_t)&entry->val; } *(VALUE *)*key = new_key; |