1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

gc.c: ObjectSpace::WeakMap#key?

* gc.c (wmap_each_i): add ObjectSpace::WeakMap#key? method.

* lib/weakref.rb (WeakRef#weakref_alive): use above method.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43351 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-10-18 06:59:12 +00:00
parent b443d83a77
commit e12799fd31
2 changed files with 11 additions and 1 deletions

10
gc.c
View file

@ -5305,6 +5305,13 @@ wmap_aref(VALUE self, VALUE wmap)
return obj;
}
/* Returns +true+ if +key+ is registered */
static VALUE
wmap_has_key(VALUE self, VALUE key)
{
return NIL_P(wmap_aref(self, key)) ? Qfalse : Qtrue;
}
/*
------------------------------ GC profiler ------------------------------
@ -6081,6 +6088,9 @@ Init_GC(void)
rb_define_alloc_func(rb_cWeakMap, wmap_allocate);
rb_define_method(rb_cWeakMap, "[]=", wmap_aset, 2);
rb_define_method(rb_cWeakMap, "[]", wmap_aref, 1);
rb_define_method(rb_cWeakMap, "include?", wmap_has_key, 1);
rb_define_method(rb_cWeakMap, "member?", wmap_has_key, 1);
rb_define_method(rb_cWeakMap, "key?", wmap_has_key, 0);
rb_define_private_method(rb_cWeakMap, "finalize", wmap_finalize, 1);
}

View file

@ -101,7 +101,7 @@ class WeakRef < Delegator
# Returns true if the referenced object is still alive.
def weakref_alive?
!!(@@__map[self] or defined?(@delegate_sd_obj))
@@__map.key?(self) or defined?(@delegate_sd_obj)
end
end