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
This commit is contained in:
parent
bcdad3299b
commit
27947a449f
26
gc.c
26
gc.c
@ -6508,12 +6508,25 @@ wmap_values(VALUE self)
|
|||||||
return args.value;
|
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 */
|
/* Creates a weak reference from the given key to the given value */
|
||||||
static VALUE
|
static VALUE
|
||||||
wmap_aset(VALUE self, VALUE wmap, VALUE orig)
|
wmap_aset(VALUE self, VALUE wmap, VALUE orig)
|
||||||
{
|
{
|
||||||
st_data_t data;
|
|
||||||
VALUE rids;
|
|
||||||
struct weakmap *w;
|
struct weakmap *w;
|
||||||
|
|
||||||
TypedData_Get_Struct(self, struct weakmap, &weakmap_type, 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);
|
should_be_finalizable(wmap);
|
||||||
define_final0(orig, w->final);
|
define_final0(orig, w->final);
|
||||||
define_final0(wmap, w->final);
|
define_final0(wmap, w->final);
|
||||||
if (st_lookup(w->obj2wmap, (st_data_t)orig, &data)) {
|
st_update(w->obj2wmap, (st_data_t)orig, wmap_aset_update, wmap);
|
||||||
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_insert(w->wmap2obj, (st_data_t)wmap, (st_data_t)orig);
|
st_insert(w->wmap2obj, (st_data_t)wmap, (st_data_t)orig);
|
||||||
return nonspecial_obj_id(orig);
|
return nonspecial_obj_id(orig);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user