From 27947a449f885e71bbb62fcffcd3545cb28dcae0 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 10 Dec 2013 07:16:08 +0000 Subject: [PATCH] gc.c: use st_update * gc.c (wmap_aset): use st_update instead of st_lookup and st_insert. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44118 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- gc.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/gc.c b/gc.c index 081f997e45..154febc08a 100644 --- a/gc.c +++ b/gc.c @@ -6508,12 +6508,25 @@ wmap_values(VALUE self) return args.value; } +static int +wmap_aset_update(st_data_t *key, st_data_t *val, st_data_t arg, int existing) +{ + if (existing) { + rb_ary_push((VALUE)*val, (VALUE)arg); + return ST_STOP; + } + else { + VALUE ary = rb_ary_tmp_new(1); + *val = (st_data_t)ary; + rb_ary_push(ary, (VALUE)arg); + } + return ST_CONTINUE; +} + /* Creates a weak reference from the given key to the given value */ static VALUE wmap_aset(VALUE self, VALUE wmap, VALUE orig) { - st_data_t data; - VALUE rids; struct weakmap *w; TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w); @@ -6521,14 +6534,7 @@ wmap_aset(VALUE self, VALUE wmap, VALUE orig) should_be_finalizable(wmap); define_final0(orig, w->final); define_final0(wmap, w->final); - if (st_lookup(w->obj2wmap, (st_data_t)orig, &data)) { - rids = (VALUE)data; - } - else { - rids = rb_ary_tmp_new(1); - st_insert(w->obj2wmap, (st_data_t)orig, (st_data_t)rids); - } - rb_ary_push(rids, wmap); + st_update(w->obj2wmap, (st_data_t)orig, wmap_aset_update, wmap); st_insert(w->wmap2obj, (st_data_t)wmap, (st_data_t)orig); return nonspecial_obj_id(orig); }