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

ruby-changes:74228

From: Yusuke <ko1@a...>
Date: Mon, 24 Oct 2022 18:22:11 +0900 (JST)
Subject: [ruby-changes:74228] 67ed70da61 (master): Refactor timeout-setting code to a function

https://git.ruby-lang.org/ruby.git/commit/?id=67ed70da61

From 67ed70da615c7fa5dc46c30eb3e966b903ef1f8b Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Mon, 24 Oct 2022 18:21:30 +0900
Subject: Refactor timeout-setting code to a function

---
 re.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/re.c b/re.c
index b21def1b7b..c65e4a58eb 100644
--- a/re.c
+++ b/re.c
@@ -3731,6 +3731,16 @@ str_to_option(VALUE str) https://github.com/ruby/ruby/blob/trunk/re.c#L3731
     return flag;
 }
 
+static void
+set_timeout(rb_hrtime_t *hrt, VALUE timeout)
+{
+    double timeout_d = NIL_P(timeout) ? 0.0 : NUM2DBL(timeout);
+    if (!NIL_P(timeout) && timeout_d <= 0) {
+        rb_raise(rb_eArgError, "invalid timeout: %"PRIsVALUE, timeout);
+    }
+    double2hrtime(hrt, timeout_d);
+}
+
 /*
  *  call-seq:
  *    Regexp.new(string, options = 0, n_flag = nil, timeout: nil) -> regexp
@@ -3847,13 +3857,7 @@ rb_reg_initialize_m(int argc, VALUE *argv, VALUE self) https://github.com/ruby/ruby/blob/trunk/re.c#L3857
 
     regex_t *reg = RREGEXP_PTR(self);
 
-    {
-        double timeout_d = NIL_P(timeout) ? 0.0 : NUM2DBL(timeout);
-        if (!NIL_P(timeout) && timeout_d <= 0) {
-            rb_raise(rb_eArgError, "invalid timeout: %"PRIsVALUE, timeout);
-        }
-        double2hrtime(&reg->timelimit, timeout_d);
-    }
+    set_timeout(&reg->timelimit, timeout);
 
     return self;
 }
@@ -4478,14 +4482,9 @@ rb_reg_s_timeout_get(VALUE dummy) https://github.com/ruby/ruby/blob/trunk/re.c#L4482
 static VALUE
 rb_reg_s_timeout_set(VALUE dummy, VALUE timeout)
 {
-    double timeout_d = NIL_P(timeout) ? 0.0 : NUM2DBL(timeout);
-
     rb_ractor_ensure_main_ractor("can not access Regexp.timeout from non-main Ractors");
 
-    if (!NIL_P(timeout) && timeout_d <= 0) {
-        rb_raise(rb_eArgError, "invalid timeout: %"PRIsVALUE, timeout);
-    }
-    double2hrtime(&rb_reg_match_time_limit, timeout_d);
+    set_timeout(&rb_reg_match_time_limit, timeout);
 
     return timeout;
 }
-- 
cgit v1.2.3


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

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