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

ruby-changes:32063

From: nobu <ko1@a...>
Date: Thu, 12 Dec 2013 11:01:25 +0900 (JST)
Subject: [ruby-changes:32063] nobu:r44142 (trunk): gc.c: live keys only

nobu	2013-12-12 11:01:18 +0900 (Thu, 12 Dec 2013)

  New Revision: 44142

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

  Log:
    gc.c: live keys only
    
    * gc.c (wmap_keys): return keys for live objects only, like as
      wmap_values.

  Modified files:
    trunk/gc.c
Index: gc.c
===================================================================
--- gc.c	(revision 44141)
+++ gc.c	(revision 44142)
@@ -6476,7 +6476,13 @@ wmap_each_value(VALUE self) https://github.com/ruby/ruby/blob/trunk/gc.c#L6476
 static int
 wmap_keys_i(st_data_t key, st_data_t val, st_data_t arg)
 {
-    rb_ary_push((VALUE)arg, (VALUE)key);
+    struct wmap_iter_arg *argp = (struct wmap_iter_arg *)arg;
+    rb_objspace_t *objspace = argp->objspace;
+    VALUE ary = argp->value;
+    VALUE obj = (VALUE)val;
+    if (is_id_value(objspace, obj) && is_live_object(objspace, obj)) {
+	rb_ary_push(ary, (VALUE)key);
+    }
     return ST_CONTINUE;
 }
 
@@ -6485,12 +6491,13 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/gc.c#L6491
 wmap_keys(VALUE self)
 {
     struct weakmap *w;
-    VALUE ary;
+    struct wmap_iter_arg args;
 
     TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w);
-    ary = rb_ary_new();
-    st_foreach(w->wmap2obj, wmap_keys_i, (st_data_t)ary);
-    return ary;
+    args.objspace = &rb_objspace;
+    args.value = rb_ary_new();
+    st_foreach(w->wmap2obj, wmap_keys_i, (st_data_t)&args);
+    return args.value;
 }
 
 static int

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

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