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

ruby-changes:59647

From: Nobuyoshi <ko1@a...>
Date: Wed, 8 Jan 2020 18:44:05 +0900 (JST)
Subject: [ruby-changes:59647] 5b06dd3a42 (master): Hoisted out call_default_proc

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

From 5b06dd3a4237114aac093e560abe24f87536b621 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Wed, 8 Jan 2020 18:13:35 +0900
Subject: Hoisted out call_default_proc


diff --git a/hash.c b/hash.c
index d99d41a..4f72b4c 100644
--- a/hash.c
+++ b/hash.c
@@ -1942,17 +1942,21 @@ rb_hash_rehash(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L1942
     return hash;
 }
 
+static VALUE
+call_default_proc(VALUE proc, VALUE hash, VALUE key)
+{
+    VALUE args[2] = {hash, key};
+    return rb_proc_call_with_block(proc, 2, args, Qnil);
+}
+
 VALUE
 rb_hash_default_value(VALUE hash, VALUE key)
 {
-    VALUE args[2];
     if (LIKELY(rb_method_basic_definition_p(CLASS_OF(hash), id_default))) {
 	VALUE ifnone = RHASH_IFNONE(hash);
         if (!FL_TEST(hash, RHASH_PROC_DEFAULT)) return ifnone;
 	if (key == Qundef) return Qnil;
-        args[0] = hash;
-        args[1] = key;
-        return rb_proc_call_with_block(ifnone, 2, args, Qnil);
+        return call_default_proc(ifnone, hash, key);
     }
     else {
 	return rb_funcall(hash, id_default, 1, key);
@@ -2119,15 +2123,13 @@ rb_hash_fetch(VALUE hash, VALUE key) https://github.com/ruby/ruby/blob/trunk/hash.c#L2123
 static VALUE
 rb_hash_default(int argc, VALUE *argv, VALUE hash)
 {
-    VALUE args[2], ifnone;
+    VALUE ifnone;
 
     rb_check_arity(argc, 0, 1);
     ifnone = RHASH_IFNONE(hash);
     if (FL_TEST(hash, RHASH_PROC_DEFAULT)) {
 	if (argc == 0) return Qnil;
-	args[0] = hash;
-	args[1] = argv[0];
-        return rb_proc_call_with_block(ifnone, 2, args, Qnil);
+	return call_default_proc(ifnone, hash, argv[0]);
     }
     return ifnone;
 }
-- 
cgit v0.10.2


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

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