summaryrefslogtreecommitdiff
path: root/iseq.c
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2022-09-23 22:54:39 +1200
committerSamuel Williams <samuel.williams@oriontransfer.co.nz>2022-09-25 20:35:47 +1300
commit09ea4f3a9fc13214198fa2cf223ec601640d3eac (patch)
treedaee36b5c00bd2a434aed98accf3704e3a0382bf /iseq.c
parent205c252ec7364ea30ab39cc3c316fdada781eb1b (diff)
downloadruby-09ea4f3a9fc13214198fa2cf223ec601640d3eac.tar.gz
Extract common code for coverage setup.
Diffstat (limited to 'iseq.c')
-rw-r--r--iseq.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/iseq.c b/iseq.c
index 9359fcfe4e..44c4f6697b 100644
--- a/iseq.c
+++ b/iseq.c
@@ -899,17 +899,29 @@ ast_line_count(const rb_ast_body_t *ast)
return FIX2INT(ast->script_lines);
}
+static VALUE
+iseq_setup_coverage(VALUE coverages, VALUE path, const rb_ast_body_t *ast, int line_offset)
+{
+ int line_count = line_offset + ast_line_count(ast);
+
+ if (line_count >= 0) {
+ int len = (rb_get_coverage_mode() & COVERAGE_TARGET_ONESHOT_LINES) ? 0 : line_count;
+
+ VALUE coverage = rb_default_coverage(len);
+ rb_hash_aset(coverages, path, coverage);
+
+ return coverage;
+ }
+
+ return Qnil;
+}
+
rb_iseq_t *
rb_iseq_new_top(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent)
{
VALUE coverages = rb_get_coverages();
if (RTEST(coverages)) {
- int line_count = ast_line_count(ast);
- if (line_count >= 0) {
- int len = (rb_get_coverage_mode() & COVERAGE_TARGET_ONESHOT_LINES) ? 0 : line_count;
- VALUE coverage = rb_default_coverage(len);
- rb_hash_aset(coverages, path, coverage);
- }
+ iseq_setup_coverage(coverages, path, ast, 0);
}
return rb_iseq_new_with_opt(ast, name, path, realpath, INT2FIX(0), parent, 0,
@@ -930,13 +942,7 @@ rb_iseq_new_eval(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpat
VALUE coverages = rb_get_coverages();
if (RTEST(coverages) && RTEST(path) && !RTEST(rb_hash_has_key(coverages, path))) {
int line_offset = RB_NUM2INT(first_lineno) - 1;
- int line_count = line_offset + ast_line_count(ast);
-
- if (line_count >= 0) {
- int len = (rb_get_coverage_mode() & COVERAGE_TARGET_ONESHOT_LINES) ? 0 : line_count;
- VALUE coverage = rb_default_coverage(len);
- rb_hash_aset(coverages, path, coverage);
- }
+ iseq_setup_coverage(coverages, path, ast, line_offset);
}
return rb_iseq_new_with_opt(ast, name, path, realpath, first_lineno,