mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user