summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-06 07:04:48 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-06 07:04:48 +0000
commitc3c0c0745f6192b31fdc162d91b9bc2379be182b (patch)
tree45371199c2c48685706bd7459afa2b34583a301a /thread.c
parentec1d41ba0e119089ec4df4b58e5c12eb17aedc79 (diff)
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61046 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/thread.c b/thread.c
index 43c6f224b5..5c7f1909f2 100644
--- a/thread.c
+++ b/thread.c
@@ -4999,26 +4999,19 @@ update_line_coverage(VALUE data, const rb_trace_arg_t *trace_arg)
}
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 mode, VALUE me2counter)
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)
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);
}