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
This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-06-30 12:07:38 +09:00
parent 90fd382a9e
commit f3c4d64a5e
+9 -2
View File
@@ -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