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

ruby-changes:48928

From: mame <ko1@a...>
Date: Wed, 6 Dec 2017 16:04:52 +0900 (JST)
Subject: [ruby-changes:48928] mame:r61046 (trunk): thread.c (update_branch_coverage): renamed from `update_coverage`

mame	2017-12-06 16:04:48 +0900 (Wed, 06 Dec 2017)

  New Revision: 61046

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

  Log:
    thread.c (update_branch_coverage): renamed from `update_coverage`
    
    Now this function only deals with branch events, so this change renames
    it and remove complexity that is no longer needed.

  Modified files:
    trunk/compile.c
    trunk/thread.c
Index: compile.c
===================================================================
--- compile.c	(revision 61045)
+++ compile.c	(revision 61046)
@@ -288,7 +288,7 @@ struct iseq_compile_data_ensure_node_sta https://github.com/ruby/ruby/blob/trunk/compile.c#L288
 	  rb_ary_push(branches, INT2FIX(last_line)); \
 	  rb_ary_push(branches, INT2FIX(last_column)); \
 	  rb_ary_push(branches, INT2FIX(counter_idx)); \
-	  ADD_INSN2((seq), (first_line), trace2, INT2FIX(RUBY_EVENT_COVERAGE), INT2FIX(counter_idx * 16 + COVERAGE_INDEX_BRANCHES)); \
+	  ADD_INSN2((seq), (first_line), trace2, INT2FIX(RUBY_EVENT_COVERAGE), INT2FIX(counter_idx)); \
       } \
   } while (0)
 
Index: thread.c
===================================================================
--- thread.c	(revision 61045)
+++ thread.c	(revision 61046)
@@ -4999,26 +4999,19 @@ update_line_coverage(VALUE data, const r https://github.com/ruby/ruby/blob/trunk/thread.c#L4999
 }
 
 static void
-update_coverage(VALUE data, const rb_trace_arg_t *trace_arg)
+update_branch_coverage(VALUE data, const rb_trace_arg_t *trace_arg)
 {
     VALUE coverage = rb_iseq_coverage(GET_EC()->cfp->iseq);
     if (RB_TYPE_P(coverage, T_ARRAY) && !RBASIC_CLASS(coverage)) {
-	long arg = FIX2INT(trace_arg->data);
-	switch (arg % 16) {
-	  case COVERAGE_INDEX_BRANCHES: {
-	    VALUE branches = RARRAY_AREF(coverage, COVERAGE_INDEX_BRANCHES);
-	    if (branches) {
-		long count;
-		long idx = arg / 16;
-		VALUE counters = RARRAY_AREF(branches, 1);
-		VALUE num = RARRAY_AREF(counters, idx);
-		count = FIX2LONG(num) + 1;
-		if (POSFIXABLE(count)) {
-		    RARRAY_ASET(counters, idx, LONG2FIX(count));
-		}
+	VALUE branches = RARRAY_AREF(coverage, COVERAGE_INDEX_BRANCHES);
+	if (branches) {
+	    long idx = FIX2INT(trace_arg->data), count;
+	    VALUE counters = RARRAY_AREF(branches, 1);
+	    VALUE num = RARRAY_AREF(counters, idx);
+	    count = FIX2LONG(num) + 1;
+	    if (POSFIXABLE(count)) {
+		RARRAY_ASET(counters, idx, LONG2FIX(count));
 	    }
-	    break;
-	  }
 	}
     }
 }
@@ -5112,7 +5105,9 @@ rb_set_coverages(VALUE coverages, int mo https://github.com/ruby/ruby/blob/trunk/thread.c#L5105
     GET_VM()->coverages = coverages;
     GET_VM()->coverage_mode = mode;
     rb_add_event_hook2((rb_event_hook_func_t) update_line_coverage, RUBY_EVENT_LINE, Qnil, RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG);
-    rb_add_event_hook2((rb_event_hook_func_t) update_coverage, RUBY_EVENT_COVERAGE, Qnil, RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG);
+    if (mode & COVERAGE_TARGET_BRANCHES) {
+	rb_add_event_hook2((rb_event_hook_func_t) update_branch_coverage, RUBY_EVENT_COVERAGE, Qnil, RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG);
+    }
     if (mode & COVERAGE_TARGET_METHODS) {
 	rb_add_event_hook2((rb_event_hook_func_t) update_method_coverage, RUBY_EVENT_CALL, me2counter, RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG);
     }
@@ -5136,10 +5131,10 @@ rb_reset_coverages(void) https://github.com/ruby/ruby/blob/trunk/thread.c#L5131
     VALUE coverages = rb_get_coverages();
     st_foreach(rb_hash_tbl_raw(coverages), reset_coverage_i, 0);
     GET_VM()->coverages = Qfalse;
-    if (GET_VM()->coverage_mode & COVERAGE_TARGET_LINES) {
-	rb_remove_event_hook((rb_event_hook_func_t) update_line_coverage);
+    rb_remove_event_hook((rb_event_hook_func_t) update_line_coverage);
+    if (GET_VM()->coverage_mode & COVERAGE_TARGET_BRANCHES) {
+	rb_remove_event_hook((rb_event_hook_func_t) update_branch_coverage);
     }
-    rb_remove_event_hook((rb_event_hook_func_t) update_coverage);
     if (GET_VM()->coverage_mode & COVERAGE_TARGET_METHODS) {
 	rb_remove_event_hook((rb_event_hook_func_t) update_method_coverage);
     }

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

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