summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2020-06-19 12:48:30 +0900
committerYusuke Endoh <mame@ruby-lang.org>2020-06-20 09:28:03 +0900
commit4b523e79a0ee0070b07331dd57153c1f3a5dbca6 (patch)
tree062733f97123178604e6c0741bd1210a4c7e880c
parent37cd877dbd70745c05aab7e1e155beb5ae6ad772 (diff)
compile.c (branch_coverage_valid_p): Refactored out
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3240
-rw-r--r--compile.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/compile.c b/compile.c
index a987c626dc..2a99cf99a4 100644
--- a/compile.c
+++ b/compile.c
@@ -595,12 +595,17 @@ APPEND_ELEM(ISEQ_ARG_DECLARE LINK_ANCHOR *const anchor, LINK_ELEMENT *before, LI
#define APPEND_ELEM(anchor, before, elem) APPEND_ELEM(iseq, (anchor), (before), (elem))
#endif
+static int branch_coverage_valid_p(rb_iseq_t *iseq, int first_line)
+{
+ if (!ISEQ_COVERAGE(iseq)) return 0;
+ if (!ISEQ_BRANCH_COVERAGE(iseq)) return 0;
+ if (first_line <= 0) return 0;
+ return 1;
+}
+
static VALUE decl_branch_base(rb_iseq_t *iseq, int first_line, int first_column, int last_line, int last_column, const char *type)
{
- // check if branch coverage is enabled
- if (!ISEQ_COVERAGE(iseq)) return Qundef;
- if (!ISEQ_BRANCH_COVERAGE(iseq)) return Qundef;
- if (first_line <= 0) return Qundef;
+ if (!branch_coverage_valid_p(iseq, first_line)) return Qundef;
VALUE structure = RARRAY_AREF(ISEQ_BRANCH_COVERAGE(iseq), 0);
VALUE branches = rb_ary_tmp_new(5);
@@ -616,10 +621,7 @@ static VALUE decl_branch_base(rb_iseq_t *iseq, int first_line, int first_column,
static void add_trace_branch_coverage(rb_iseq_t *iseq, LINK_ANCHOR *const seq, int first_line, int first_column, int last_line, int last_column, const char *type, VALUE branches)
{
- // check if branch coverage is enabled
- if (!ISEQ_COVERAGE(iseq)) return;
- if (!ISEQ_BRANCH_COVERAGE(iseq)) return;
- if (first_line <= 0) return;
+ if (!branch_coverage_valid_p(iseq, first_line)) return;
VALUE counters = RARRAY_AREF(ISEQ_BRANCH_COVERAGE(iseq), 1);
long counter_idx = RARRAY_LEN(counters);