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

ruby-changes:35767

From: nobu <ko1@a...>
Date: Wed, 8 Oct 2014 23:50:04 +0900 (JST)
Subject: [ruby-changes:35767] nobu:r47849 (trunk): variable.c: use st_update

nobu	2014-10-08 23:49:49 +0900 (Wed, 08 Oct 2014)

  New Revision: 47849

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

  Log:
    variable.c: use st_update
    
    * variable.c (generic_ivar_set): use st_update to insert object
      which does not have generic instance variables yet.

  Modified files:
    trunk/variable.c
Index: variable.c
===================================================================
--- variable.c	(revision 47848)
+++ variable.c	(revision 47849)
@@ -930,11 +930,27 @@ generic_ivar_get(VALUE obj, ID id, VALUE https://github.com/ruby/ruby/blob/trunk/variable.c#L930
     return undef;
 }
 
+static int
+generic_ivar_update(st_data_t *k, st_data_t *v, st_data_t a, int existing)
+{
+    VALUE obj = (VALUE)*k;
+    st_table **tbl = (st_table **)a;
+
+    if (!existing) {
+	FL_SET(obj, FL_EXIVAR);
+	*v = (st_data_t)(*tbl = st_init_numtable());
+	return ST_CONTINUE;
+    }
+    else {
+	*tbl = (st_table *)*v;
+	return ST_STOP;
+    }
+}
+
 static void
 generic_ivar_set(VALUE obj, ID id, VALUE val)
 {
     st_table *tbl;
-    st_data_t data;
 
     if (rb_special_const_p(obj)) {
 	if (rb_obj_frozen_p(obj)) rb_error_frozen("object");
@@ -943,16 +959,14 @@ generic_ivar_set(VALUE obj, ID id, VALUE https://github.com/ruby/ruby/blob/trunk/variable.c#L959
     if (!generic_iv_tbl) {
 	generic_iv_tbl = st_init_numtable();
     }
-    if (!st_lookup(generic_iv_tbl, (st_data_t)obj, &data)) {
-	FL_SET(obj, FL_EXIVAR);
-	tbl = st_init_numtable();
-	st_add_direct(generic_iv_tbl, (st_data_t)obj, (st_data_t)tbl);
+    if (!st_update(generic_iv_tbl, (st_data_t)obj,
+		   generic_ivar_update, (st_data_t)&tbl)) {
 	st_add_direct(tbl, (st_data_t)id, (st_data_t)val);
-	if (FL_ABLE(obj)) RB_OBJ_WRITTEN(obj, Qundef, val);
-	return;
     }
-    st_insert((st_table *)data, (st_data_t)id, (st_data_t)val);
-    if (FL_ABLE(obj)) RB_OBJ_WRITTEN(obj, data, val);
+    else {
+	st_insert(tbl, (st_data_t)id, (st_data_t)val);
+    }
+    if (FL_ABLE(obj)) RB_OBJ_WRITTEN(obj, Qundef, val);
 }
 
 static VALUE

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

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