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

ruby-changes:31651

From: nobu <ko1@a...>
Date: Wed, 20 Nov 2013 02:01:31 +0900 (JST)
Subject: [ruby-changes:31651] nobu:r43730 (trunk): eval_jump.c: reuse same tag

nobu	2013-11-20 02:01:10 +0900 (Wed, 20 Nov 2013)

  New Revision: 43730

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

  Log:
    eval_jump.c: reuse same tag
    
    * eval_jump.c (rb_exec_end_proc): reduce number of pushing/popping
      and reuse same tag.

  Modified files:
    trunk/eval_intern.h
    trunk/eval_jump.c
Index: eval_intern.h
===================================================================
--- eval_intern.h	(revision 43729)
+++ eval_intern.h	(revision 43730)
@@ -104,6 +104,12 @@ extern int select_large_fdset(int, fd_se https://github.com/ruby/ruby/blob/trunk/eval_intern.h#L104
 #define TH_POP_TAG2() \
   _th->tag = _tag.prev
 
+#define TH_PUSH_TAG2() (_th->tag = &_tag, 0)
+
+#define TH_TMPPOP_TAG() TH_POP_TAG2()
+
+#define TH_REPUSH_TAG() TH_PUSH_TAG2()
+
 #define PUSH_TAG() TH_PUSH_TAG(GET_THREAD())
 #define POP_TAG()      TH_POP_TAG()
 
@@ -128,7 +134,7 @@ rb_threadptr_tag_jump(rb_thread_t *th, i https://github.com/ruby/ruby/blob/trunk/eval_intern.h#L134
   [ISO/IEC 9899:1999] 7.13.1.1
 */
 #define TH_EXEC_TAG() \
-    (ruby_setjmp(_tag.buf) ? rb_threadptr_tag_state(_th) : (_th->tag = &_tag, 0))
+    (ruby_setjmp(_tag.buf) ? rb_threadptr_tag_state(_th) : TH_PUSH_TAG2())
 
 #define EXEC_TAG() \
   TH_EXEC_TAG()
Index: eval_jump.c
===================================================================
--- eval_jump.c	(revision 43729)
+++ eval_jump.c	(revision 43730)
@@ -93,53 +93,43 @@ rb_mark_end_proc(void) https://github.com/ruby/ruby/blob/trunk/eval_jump.c#L93
     }
 }
 
+static void
+exec_end_procs_chain(struct end_proc_data *volatile *procs)
+{
+    struct end_proc_data volatile endproc;
+    struct end_proc_data *link;
+
+    while ((link = *procs) != 0) {
+	*procs = link->next;
+	endproc = *link;
+	xfree(link);
+	rb_set_safe_level_force(endproc.safe);
+	(*endproc.func) (endproc.data);
+    }
+}
+
 void
 rb_exec_end_proc(void)
 {
-    struct end_proc_data volatile endproc;
-    struct end_proc_data volatile *link;
     int status;
     volatile int safe = rb_safe_level();
     rb_thread_t *th = GET_THREAD();
     volatile VALUE errinfo = th->errinfo;
 
-    while (ephemeral_end_procs) {
-	link = ephemeral_end_procs;
-	ephemeral_end_procs = link->next;
-	endproc = *link;
-	xfree((void *)link);
-	link = &endproc;
-
-	PUSH_TAG();
-	if ((status = EXEC_TAG()) == 0) {
-	    rb_set_safe_level_force(link->safe);
-	    (*link->func) (link->data);
-	}
-	POP_TAG();
-	if (status) {
-	    error_handle(status);
-	    if (!NIL_P(th->errinfo)) errinfo = th->errinfo;
-	}
+    PUSH_TAG();
+    if ((status = EXEC_TAG()) == 0) {
+      again:
+	exec_end_procs_chain(&ephemeral_end_procs);
+	exec_end_procs_chain(&end_procs);
     }
-
-    while (end_procs) {
-	link = end_procs;
-	end_procs = link->next;
-	endproc = *link;
-	xfree((void *)link);
-	link = &endproc;
-
-	PUSH_TAG();
-	if ((status = EXEC_TAG()) == 0) {
-	    rb_set_safe_level_force(link->safe);
-	    (*link->func) (link->data);
-	}
-	POP_TAG();
-	if (status) {
-	    error_handle(status);
-	    if (!NIL_P(th->errinfo)) errinfo = th->errinfo;
-	}
+    else {
+	TH_TMPPOP_TAG();
+	error_handle(status);
+	if (!NIL_P(th->errinfo)) errinfo = th->errinfo;
+	TH_REPUSH_TAG();
+	goto again;
     }
+    POP_TAG();
 
     rb_set_safe_level_force(safe);
     th->errinfo = errinfo;

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

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