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

ruby-changes:39171

From: normal <ko1@a...>
Date: Wed, 15 Jul 2015 17:29:42 +0900 (JST)
Subject: [ruby-changes:39171] normal:r51252 (trunk): remove redundant NULL check in mark functions

normal	2015-07-15 17:29:22 +0900 (Wed, 15 Jul 2015)

  New Revision: 51252

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

  Log:
    remove redundant NULL check in mark functions
    
    gc.c (gc_mark_children)only calls mark_func if the T_DATA ptr is
    non-NULL, so avoid redundantly checking for that in each
    mark function.
    
    * iseq.c (iseq_mark): remove check for data pointer
    * proc.c (binding_mark): ditto
    * vm.c (rb_thread_mark): ditto
    * vm_trace.c (tp_mark): ditto

  Modified files:
    trunk/ChangeLog
    trunk/iseq.c
    trunk/proc.c
    trunk/vm.c
    trunk/vm_trace.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51251)
+++ ChangeLog	(revision 51252)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jul 15 17:27:40 2015  Eric Wong  <e@8...>
+
+	* iseq.c (iseq_mark): remove check for data pointer
+	* proc.c (binding_mark): ditto
+	* vm.c (rb_thread_mark): ditto
+	* vm_trace.c (tp_mark): ditto
+
 Wed Jul 15 16:55:04 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* encoding.c (enc_autoload): drop dummy encoding flag from
Index: iseq.c
===================================================================
--- iseq.c	(revision 51251)
+++ iseq.c	(revision 51252)
@@ -102,27 +102,26 @@ iseq_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/iseq.c#L102
 static void
 iseq_mark(void *ptr)
 {
+    rb_iseq_t *iseq = ptr;
+
     RUBY_MARK_ENTER("iseq");
 
-    if (ptr) {
-	rb_iseq_t *iseq = ptr;
+    RUBY_GC_INFO("%s @ %s\n", RSTRING_PTR(iseq->location.label), RSTRING_PTR(iseq->location.path));
 
-	RUBY_GC_INFO("%s @ %s\n", RSTRING_PTR(iseq->location.label), RSTRING_PTR(iseq->location.path));
+    RUBY_MARK_UNLESS_NULL(iseq->mark_ary);
+    RUBY_MARK_UNLESS_NULL(iseq->location.label);
+    RUBY_MARK_UNLESS_NULL(iseq->location.base_label);
+    RUBY_MARK_UNLESS_NULL(iseq->location.path);
+    RUBY_MARK_UNLESS_NULL(iseq->location.absolute_path);
+    RUBY_MARK_UNLESS_NULL(iseq->coverage);
 
-	RUBY_MARK_UNLESS_NULL(iseq->mark_ary);
-	RUBY_MARK_UNLESS_NULL(iseq->location.label);
-	RUBY_MARK_UNLESS_NULL(iseq->location.base_label);
-	RUBY_MARK_UNLESS_NULL(iseq->location.path);
-	RUBY_MARK_UNLESS_NULL(iseq->location.absolute_path);
-	RUBY_MARK_UNLESS_NULL(iseq->coverage);
-
-	if (iseq->compile_data != 0) {
-	    struct iseq_compile_data *const compile_data = iseq->compile_data;
-	    RUBY_MARK_UNLESS_NULL(compile_data->mark_ary);
-	    RUBY_MARK_UNLESS_NULL(compile_data->err_info);
-	    RUBY_MARK_UNLESS_NULL(compile_data->catch_table_ary);
-	}
+    if (iseq->compile_data != 0) {
+	struct iseq_compile_data *const compile_data = iseq->compile_data;
+	RUBY_MARK_UNLESS_NULL(compile_data->mark_ary);
+	RUBY_MARK_UNLESS_NULL(compile_data->err_info);
+	RUBY_MARK_UNLESS_NULL(compile_data->catch_table_ary);
     }
+
     RUBY_MARK_LEAVE("iseq");
 }
 
Index: proc.c
===================================================================
--- proc.c	(revision 51251)
+++ proc.c	(revision 51252)
@@ -243,13 +243,13 @@ binding_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/proc.c#L243
 static void
 binding_mark(void *ptr)
 {
-    rb_binding_t *bind;
+    rb_binding_t *bind = ptr;
+
     RUBY_MARK_ENTER("binding");
-    if (ptr) {
-	bind = ptr;
-	RUBY_MARK_UNLESS_NULL(bind->env);
-	RUBY_MARK_UNLESS_NULL(bind->path);
-    }
+
+    RUBY_MARK_UNLESS_NULL(bind->env);
+    RUBY_MARK_UNLESS_NULL(bind->path);
+
     RUBY_MARK_LEAVE("binding");
 }
 
Index: vm_trace.c
===================================================================
--- vm_trace.c	(revision 51251)
+++ vm_trace.c	(revision 51252)
@@ -653,11 +653,9 @@ typedef struct rb_tp_struct { https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L653
 static void
 tp_mark(void *ptr)
 {
-    if (ptr) {
-	rb_tp_t *tp = (rb_tp_t *)ptr;
-	rb_gc_mark(tp->proc);
-	if (tp->target_th) rb_gc_mark(tp->target_th->self);
-    }
+    rb_tp_t *tp = ptr;
+    rb_gc_mark(tp->proc);
+    if (tp->target_th) rb_gc_mark(tp->target_th->self);
 }
 
 static size_t
Index: vm.c
===================================================================
--- vm.c	(revision 51251)
+++ vm.c	(revision 51252)
@@ -2053,63 +2053,61 @@ void rb_fiber_mark_self(rb_fiber_t *fib) https://github.com/ruby/ruby/blob/trunk/vm.c#L2053
 void
 rb_thread_mark(void *ptr)
 {
-    rb_thread_t *th = NULL;
+    rb_thread_t *th = ptr;
     RUBY_MARK_ENTER("thread");
-    if (ptr) {
-	th = ptr;
-	if (th->stack) {
-	    VALUE *p = th->stack;
-	    VALUE *sp = th->cfp->sp;
-	    rb_control_frame_t *cfp = th->cfp;
-	    rb_control_frame_t *limit_cfp = (void *)(th->stack + th->stack_size);
-
-	    rb_gc_mark_values((long)(sp - p), p);
-
-	    while (cfp != limit_cfp) {
-		rb_iseq_t *iseq = cfp->iseq;
-		rb_gc_mark(cfp->proc);
-		rb_gc_mark(cfp->self);
-		if (iseq) {
-		    rb_gc_mark(RUBY_VM_NORMAL_ISEQ_P(iseq) ? iseq->self : (VALUE)iseq);
-		}
-		cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
+
+    if (th->stack) {
+	VALUE *p = th->stack;
+	VALUE *sp = th->cfp->sp;
+	rb_control_frame_t *cfp = th->cfp;
+	rb_control_frame_t *limit_cfp = (void *)(th->stack + th->stack_size);
+
+	rb_gc_mark_values((long)(sp - p), p);
+
+	while (cfp != limit_cfp) {
+	    rb_iseq_t *iseq = cfp->iseq;
+	    rb_gc_mark(cfp->proc);
+	    rb_gc_mark(cfp->self);
+	    if (iseq) {
+		rb_gc_mark(RUBY_VM_NORMAL_ISEQ_P(iseq) ? iseq->self : (VALUE)iseq);
 	    }
+	    cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
 	}
+    }
 
-	/* mark ruby objects */
-	RUBY_MARK_UNLESS_NULL(th->first_proc);
-	if (th->first_proc) RUBY_MARK_UNLESS_NULL(th->first_args);
-
-	RUBY_MARK_UNLESS_NULL(th->thgroup);
-	RUBY_MARK_UNLESS_NULL(th->value);
-	RUBY_MARK_UNLESS_NULL(th->errinfo);
-	RUBY_MARK_UNLESS_NULL(th->pending_interrupt_queue);
-	RUBY_MARK_UNLESS_NULL(th->pending_interrupt_mask_stack);
-	RUBY_MARK_UNLESS_NULL(th->root_svar);
-	RUBY_MARK_UNLESS_NULL(th->top_self);
-	RUBY_MARK_UNLESS_NULL(th->top_wrapper);
-	rb_fiber_mark_self(th->fiber);
-	rb_fiber_mark_self(th->root_fiber);
-	RUBY_MARK_UNLESS_NULL(th->stat_insn_usage);
-	RUBY_MARK_UNLESS_NULL(th->last_status);
-
-	RUBY_MARK_UNLESS_NULL(th->locking_mutex);
-
-	rb_mark_tbl(th->local_storage);
-	RUBY_MARK_UNLESS_NULL(th->local_storage_recursive_hash);
-	RUBY_MARK_UNLESS_NULL(th->local_storage_recursive_hash_for_trace);
-
-	if (GET_THREAD() != th && th->machine.stack_start && th->machine.stack_end) {
-	    rb_gc_mark_machine_stack(th);
-	    rb_gc_mark_locations((VALUE *)&th->machine.regs,
-				 (VALUE *)(&th->machine.regs) +
-				 sizeof(th->machine.regs) / sizeof(VALUE));
-	}
+    /* mark ruby objects */
+    RUBY_MARK_UNLESS_NULL(th->first_proc);
+    if (th->first_proc) RUBY_MARK_UNLESS_NULL(th->first_args);
+
+    RUBY_MARK_UNLESS_NULL(th->thgroup);
+    RUBY_MARK_UNLESS_NULL(th->value);
+    RUBY_MARK_UNLESS_NULL(th->errinfo);
+    RUBY_MARK_UNLESS_NULL(th->pending_interrupt_queue);
+    RUBY_MARK_UNLESS_NULL(th->pending_interrupt_mask_stack);
+    RUBY_MARK_UNLESS_NULL(th->root_svar);
+    RUBY_MARK_UNLESS_NULL(th->top_self);
+    RUBY_MARK_UNLESS_NULL(th->top_wrapper);
+    rb_fiber_mark_self(th->fiber);
+    rb_fiber_mark_self(th->root_fiber);
+    RUBY_MARK_UNLESS_NULL(th->stat_insn_usage);
+    RUBY_MARK_UNLESS_NULL(th->last_status);
+
+    RUBY_MARK_UNLESS_NULL(th->locking_mutex);
+
+    rb_mark_tbl(th->local_storage);
+    RUBY_MARK_UNLESS_NULL(th->local_storage_recursive_hash);
+    RUBY_MARK_UNLESS_NULL(th->local_storage_recursive_hash_for_trace);
+
+    if (GET_THREAD() != th && th->machine.stack_start && th->machine.stack_end) {
+	rb_gc_mark_machine_stack(th);
+	rb_gc_mark_locations((VALUE *)&th->machine.regs,
+			     (VALUE *)(&th->machine.regs) +
+			     sizeof(th->machine.regs) / sizeof(VALUE));
+    }
 
-	RUBY_MARK_UNLESS_NULL(th->name);
+    RUBY_MARK_UNLESS_NULL(th->name);
 
-	rb_vm_trace_mark_event_hooks(&th->event_hooks);
-    }
+    rb_vm_trace_mark_event_hooks(&th->event_hooks);
 
     RUBY_MARK_LEAVE("thread");
 }

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

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