From 5bcfc53d6fa5518a194f2d0771830eb961180991 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 7 Aug 2025 14:44:48 +0200 Subject: [PATCH] set.c: use `rb_gc_mark_and_move` The `p->field = rb_gc_location(p->field)` isn't ideal because it means all references are rewritten on compaction, regardless of whether the referenced object has moved. This isn't good for caches nor for Copy-on-Write. `rb_gc_mark_and_move` avoid needless writes, and most of the time allow to have a single function for both marking and updating references. --- set.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/set.c b/set.c index f83fb0880c..c589fb4523 100644 --- a/set.c +++ b/set.c @@ -172,9 +172,7 @@ set_foreach_replace(st_data_t key, st_data_t argp, int error) static int set_replace_ref(st_data_t *key, st_data_t argp, int existing) { - if (rb_gc_location((VALUE)*key) != (VALUE)*key) { - *key = rb_gc_location((VALUE)*key); - } + rb_gc_mark_and_move((VALUE *)key); return ST_CONTINUE; }