mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Use identhash as WeakMap
As ObjectSpace::WeakMap allows FLONUM as a key, needs the special deal for its hash. [Feature #16035]
This commit is contained in:
parent
c3b64a86bc
commit
ce7942361d
2 changed files with 6 additions and 3 deletions
6
gc.c
6
gc.c
|
@ -10493,13 +10493,15 @@ static const rb_data_type_t weakmap_type = {
|
||||||
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
|
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern const struct st_hash_type rb_hashtype_ident;
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
wmap_allocate(VALUE klass)
|
wmap_allocate(VALUE klass)
|
||||||
{
|
{
|
||||||
struct weakmap *w;
|
struct weakmap *w;
|
||||||
VALUE obj = TypedData_Make_Struct(klass, struct weakmap, &weakmap_type, w);
|
VALUE obj = TypedData_Make_Struct(klass, struct weakmap, &weakmap_type, w);
|
||||||
w->obj2wmap = st_init_numtable();
|
w->obj2wmap = st_init_table(&rb_hashtype_ident);
|
||||||
w->wmap2obj = st_init_numtable();
|
w->wmap2obj = st_init_table(&rb_hashtype_ident);
|
||||||
w->final = rb_obj_method(obj, ID2SYM(rb_intern("finalize")));
|
w->final = rb_obj_method(obj, ID2SYM(rb_intern("finalize")));
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
3
hash.c
3
hash.c
|
@ -330,7 +330,8 @@ rb_ident_hash(st_data_t n)
|
||||||
return (st_index_t)st_index_hash((st_index_t)n);
|
return (st_index_t)st_index_hash((st_index_t)n);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct st_hash_type identhash = {
|
#define identhash rb_hashtype_ident
|
||||||
|
const struct st_hash_type rb_hashtype_ident = {
|
||||||
rb_ident_cmp,
|
rb_ident_cmp,
|
||||||
rb_ident_hash,
|
rb_ident_hash,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue