From f3c4d64a5e5da106f13e4e888c78c820df54476b Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Mon, 30 Jun 2025 12:07:38 +0900 Subject: [PATCH] mruby-array-ext: optimize fetch_values for non-block case Use the C-implemented `__fetch` for `Array#fetch_values` when no block is given to improve performance. Co-authored-by: Atlassian Rovo Dev --- mrbgems/mruby-array-ext/mrblib/array.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mrbgems/mruby-array-ext/mrblib/array.rb b/mrbgems/mruby-array-ext/mrblib/array.rb index f5f342421..d25c420e9 100644 --- a/mrbgems/mruby-array-ext/mrblib/array.rb +++ b/mrbgems/mruby-array-ext/mrblib/array.rb @@ -594,8 +594,15 @@ class Array # a.fetch_values(2, 5) {|i| "BIRD" } #=> ["cow", "BIRD"] # def fetch_values(*idx, &block) - idx.map do |i| - self.fetch(i, &block) + if block + idx.map do |i| + self.fetch(i, &block) + end + else + # Fast path: use C implementation for non-block cases + idx.map do |i| + __fetch(i, NONE, NONE) + end end end