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

ruby-changes:43649

From: nobu <ko1@a...>
Date: Fri, 22 Jul 2016 06:28:42 +0900 (JST)
Subject: [ruby-changes:43649] nobu:r55722 (trunk): gc.c: reduce EXEC_TAG

nobu	2016-07-22 06:28:34 +0900 (Fri, 22 Jul 2016)

  New Revision: 55722

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

  Log:
    gc.c: reduce EXEC_TAG
    
    * gc.c (run_finalizer): push and exec tag just once, instead of
      protecting for each finalizer.

  Modified files:
    trunk/ChangeLog
    trunk/gc.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55721)
+++ ChangeLog	(revision 55722)
@@ -1,4 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Fri Jul 22 06:12:51 2016  Nobuyoshi Nakada  <nobu@r...>
+Fri Jul 22 06:28:32 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* gc.c (run_finalizer): push and exec tag just once, instead of
+	  protecting for each finalizer.
 
 	* gc.c (gc_start_internal, rb_gc_start): set finalizing flag
 	  whenever calling deferred finalizers not to recurse.
Index: gc.c
===================================================================
--- gc.c	(revision 55721)
+++ gc.c	(revision 55722)
@@ -2691,36 +2691,41 @@ rb_gc_copy_finalizer(VALUE dest, VALUE o https://github.com/ruby/ruby/blob/trunk/gc.c#L2691
 }
 
 static VALUE
-run_single_final(VALUE arg)
+run_single_final(VALUE final, VALUE objid)
 {
-    VALUE *args = (VALUE *)arg;
+    const VALUE cmd = RARRAY_AREF(final, 1);
+    const int level = OBJ_TAINTED(cmd) ?
+	RUBY_SAFE_LEVEL_MAX : FIX2INT(RARRAY_AREF(final, 0));
 
-    return rb_check_funcall(args[0], idCall, 1, args+1);
+    rb_set_safe_level_force(level);
+    return rb_check_funcall(cmd, idCall, 1, &objid);
 }
 
 static void
 run_finalizer(rb_objspace_t *objspace, VALUE obj, VALUE table)
 {
     long i;
-    VALUE args[2];
+    int status;
     const int safe = rb_safe_level();
     const VALUE errinfo = rb_errinfo();
-
-    args[1] = nonspecial_obj_id(obj);
-
-    for (i=0; i<RARRAY_LEN(table); i++) {
-	const VALUE final = RARRAY_AREF(table, i);
-	const VALUE cmd = RARRAY_AREF(final, 1);
-	const int level = OBJ_TAINTED(cmd) ?
-	    RUBY_SAFE_LEVEL_MAX : FIX2INT(RARRAY_AREF(final, 0));
-	int status = 0;
-
-	args[0] = cmd;
-	rb_set_safe_level_force(level);
-	rb_protect(run_single_final, (VALUE)args, &status);
+    const VALUE objid = nonspecial_obj_id(obj);
+    rb_thread_t *const th = GET_THREAD();
+    volatile long finished = 0;
+
+    TH_PUSH_TAG(th);
+    status = TH_EXEC_TAG();
+    if (status) {
+	++finished;		/* skip failed finalizer */
+	rb_set_safe_level_force(safe);
+	rb_set_errinfo(errinfo);
+    }
+    for (i = finished; i<RARRAY_LEN(table); i++) {
+	finished = i;
+	run_single_final(RARRAY_AREF(table, i), objid);
 	rb_set_safe_level_force(safe);
 	rb_set_errinfo(errinfo);
     }
+    TH_POP_TAG();
 }
 
 static void

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

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