From 11edc286d837f66b37433e7d51c8b8f500e1be84 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Thu, 15 Jan 2026 20:32:20 +0900 Subject: Make `Array#map` and `Array#select` more tolerant Only when YJIT is enabled, the redefinition of `Array#<<` affects these methods. --- array.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'array.rb') 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 -- cgit v1.2.3