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

ruby-changes:32039

From: nobu <ko1@a...>
Date: Tue, 10 Dec 2013 16:16:15 +0900 (JST)
Subject: [ruby-changes:32039] nobu:r44118 (trunk): gc.c: use st_update

nobu	2013-12-10 16:16:08 +0900 (Tue, 10 Dec 2013)

  New Revision: 44118

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

  Log:
    gc.c: use st_update
    
    * gc.c (wmap_aset): use st_update instead of st_lookup and
      st_insert.

  Modified files:
    trunk/gc.c
Index: gc.c
===================================================================
--- gc.c	(revision 44117)
+++ gc.c	(revision 44118)
@@ -6508,12 +6508,25 @@ wmap_values(VALUE self) https://github.com/ruby/ruby/blob/trunk/gc.c#L6508
     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 */
 static VALUE
 wmap_aset(VALUE self, VALUE wmap, VALUE orig)
 {
-    st_data_t data;
-    VALUE rids;
     struct weakmap *w;
 
     TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w);
@@ -6521,14 +6534,7 @@ wmap_aset(VALUE self, VALUE wmap, VALUE https://github.com/ruby/ruby/blob/trunk/gc.c#L6534
     should_be_finalizable(wmap);
     define_final0(orig, w->final);
     define_final0(wmap, w->final);
-    if (st_lookup(w->obj2wmap, (st_data_t)orig, &data)) {
-	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_update(w->obj2wmap, (st_data_t)orig, wmap_aset_update, wmap);
     st_insert(w->wmap2obj, (st_data_t)wmap, (st_data_t)orig);
     return nonspecial_obj_id(orig);
 }

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

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