summaryrefslogtreecommitdiff
path: root/array.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2026-01-15 20:32:20 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2026-01-15 20:32:20 +0900
commit11edc286d837f66b37433e7d51c8b8f500e1be84 (patch)
treee5afcfa53807e17814da4b70b442515e0cf6fada /array.rb
parent6afac93c5c7178c4d836e0ec2b4b3092373ca121 (diff)
Make `Array#map` and `Array#select` more tolerant
Only when YJIT is enabled, the redefinition of `Array#<<` affects these methods.
Diffstat (limited to 'array.rb')
-rw-r--r--array.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/array.rb b/array.rb
index 03663dbb0b..81beff0b1c 100644
--- a/array.rb
+++ b/array.rb
@@ -245,7 +245,8 @@ class Array
value = nil
result = Primitive.ary_sized_alloc
while Primitive.cexpr!(%q{ ary_fetch_next(self, LOCAL_PTR(_i), LOCAL_PTR(value)) })
- result << yield(value)
+ value = yield(value)
+ Primitive.cexpr!(%q{ rb_ary_push(result, value) })
end
result
end
@@ -270,7 +271,9 @@ class Array
value = nil
result = Primitive.ary_sized_alloc
while Primitive.cexpr!(%q{ ary_fetch_next(self, LOCAL_PTR(_i), LOCAL_PTR(value)) })
- result << value if yield value
+ if yield value
+ Primitive.cexpr!(%q{ rb_ary_push(result, value) })
+ end
end
result
end