[前][次][番号順一覧][スレッド一覧]

ruby-changes:31272

From: nobu <ko1@a...>
Date: Fri, 18 Oct 2013 15:59:17 +0900 (JST)
Subject: [ruby-changes:31272] nobu:r43351 (trunk): gc.c: ObjectSpace::WeakMap#key?

nobu	2013-10-18 15:59:12 +0900 (Fri, 18 Oct 2013)

  New Revision: 43351

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43351

  Log:
    gc.c: ObjectSpace::WeakMap#key?
    
    * gc.c (wmap_each_i): add ObjectSpace::WeakMap#key? method.
    
    * lib/weakref.rb (WeakRef#weakref_alive): use above method.

  Modified files:
    trunk/gc.c
    trunk/lib/weakref.rb
Index: lib/weakref.rb
===================================================================
--- lib/weakref.rb	(revision 43350)
+++ lib/weakref.rb	(revision 43351)
@@ -101,7 +101,7 @@ class WeakRef < Delegator https://github.com/ruby/ruby/blob/trunk/lib/weakref.rb#L101
   # 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
 
Index: gc.c
===================================================================
--- gc.c	(revision 43350)
+++ gc.c	(revision 43351)
@@ -5305,6 +5305,13 @@ wmap_aref(VALUE self, VALUE wmap) https://github.com/ruby/ruby/blob/trunk/gc.c#L5305
     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) https://github.com/ruby/ruby/blob/trunk/gc.c#L6088
 	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);
     }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]