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

ruby-changes:72918

From: Nobuyoshi <ko1@a...>
Date: Fri, 12 Aug 2022 16:58:23 +0900 (JST)
Subject: [ruby-changes:72918] b2205cd45c (master): Short-circuit `Process._fork`

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

From b2205cd45c64c8aaaa19d71836522d8aaac324d5 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 14 Jul 2022 17:39:03 +0900
Subject: Short-circuit `Process._fork`

---
 process.c | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/process.c b/process.c
index 0e4dbc40f4..57df2dc06f 100644
--- a/process.c
+++ b/process.c
@@ -4328,12 +4328,30 @@ rb_fork_ruby(int *status) https://github.com/ruby/ruby/blob/trunk/process.c#L4328
     return pid;
 }
 
+static rb_pid_t
+proc_fork_pid(void)
+{
+    rb_pid_t pid = rb_fork_ruby(NULL);
+
+    if (pid == -1) {
+        rb_sys_fail("fork(2)");
+    }
+
+    return pid;
+}
+
 rb_pid_t
 rb_call_proc__fork(void)
 {
-    VALUE pid = rb_funcall(rb_mProcess, rb_intern("_fork"), 0);
-
-    return NUM2PIDT(pid);
+    ID id__fork;
+    CONST_ID(id__fork, "_fork");
+    if (rb_method_basic_definition_p(CLASS_OF(rb_mProcess), id__fork)) {
+        return proc_fork_pid();
+    }
+    else {
+        VALUE pid = rb_funcall(rb_mProcess, id__fork, 0);
+        return NUM2PIDT(pid);
+    }
 }
 #endif
 
@@ -4360,12 +4378,7 @@ rb_call_proc__fork(void) https://github.com/ruby/ruby/blob/trunk/process.c#L4378
 VALUE
 rb_proc__fork(VALUE _obj)
 {
-    rb_pid_t pid = rb_fork_ruby(NULL);
-
-    if (pid == -1) {
-        rb_sys_fail("fork(2)");
-    }
-
+    rb_pid_t pid = proc_fork_pid();
     return PIDT2NUM(pid);
 }
 
-- 
cgit v1.2.1


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

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