ruby-changes:56832
From: Aaron <ko1@a...>
Date: Tue, 6 Aug 2019 00:56:08 +0900 (JST)
Subject: [ruby-changes:56832] Aaron Patterson: 33d7a58ffb (master): add compaction support to weak maps
https://git.ruby-lang.org/ruby.git/commit/?id=33d7a58ffb From 33d7a58ffb193cb2ca200ff5b3c649a72d190d21 Mon Sep 17 00:00:00 2001 From: Aaron Patterson <tenderlove@r...> Date: Thu, 1 Aug 2019 13:44:54 -0700 Subject: add compaction support to weak maps diff --git a/gc.c b/gc.c index 3684133..7a948a7 100644 --- a/gc.c +++ b/gc.c @@ -10129,25 +10129,18 @@ wmap_mark_map(st_data_t key, st_data_t val, st_data_t arg) https://github.com/ruby/ruby/blob/trunk/gc.c#L10129 } #endif -static int -wmap_pin_obj(st_data_t key, st_data_t val, st_data_t arg) +static void +wmap_compact(void *ptr) { - rb_objspace_t *objspace = (rb_objspace_t *)arg; - VALUE obj = (VALUE)val; - if (obj && is_live_object(objspace, obj)) { - gc_pin(objspace, obj); - } - else { - return ST_DELETE; - } - return ST_CONTINUE; + struct weakmap *w = ptr; + if (w->wmap2obj) rb_gc_update_tbl_refs(w->wmap2obj); + if (w->obj2wmap) rb_gc_update_tbl_refs(w->obj2wmap); } static void wmap_mark(void *ptr) { struct weakmap *w = ptr; - if (w->wmap2obj) st_foreach(w->wmap2obj, wmap_pin_obj, (st_data_t)&rb_objspace); #if WMAP_DELETE_DEAD_OBJECT_IN_MARK if (w->obj2wmap) st_foreach(w->obj2wmap, wmap_mark_map, (st_data_t)&rb_objspace); #endif @@ -10197,6 +10190,7 @@ static const rb_data_type_t weakmap_type = { https://github.com/ruby/ruby/blob/trunk/gc.c#L10190 wmap_mark, wmap_free, wmap_memsize, + wmap_compact, }, 0, 0, RUBY_TYPED_FREE_IMMEDIATELY }; -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/