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

ruby-changes:73724

From: Samuel <ko1@a...>
Date: Sun, 25 Sep 2022 16:36:03 +0900 (JST)
Subject: [ruby-changes:73724] 09ea4f3a9f (master): Extract common code for coverage setup.

https://git.ruby-lang.org/ruby.git/commit/?id=09ea4f3a9f

From 09ea4f3a9fc13214198fa2cf223ec601640d3eac Mon Sep 17 00:00:00 2001
From: Samuel Williams <samuel.williams@o...>
Date: Fri, 23 Sep 2022 22:54:39 +1200
Subject: Extract common code for coverage setup.

---
 iseq.c | 32 +++++++++++++++++++-------------
 1 file 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) https://github.com/ruby/ruby/blob/trunk/iseq.c#L899
     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 https://github.com/ruby/ruby/blob/trunk/iseq.c#L942
     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,
-- 
cgit v1.2.1


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

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