Commit 85de02a7

85de02a7d573Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · +2 added · ~2 modified

Description

Implement Array#select!/reject!/keep_if/delete_if on typed arrays

These in-place filters were unresolved for int/str/float/sym/poly arrays. Compact the surviving elements to the front and truncate the length, returning the receiver. select!/filter!/keep_if keep elements the block accepts; reject!/delete_if drop them. Elements keep their type, so no element-type guard is needed.

(CRuby's select!/reject! return nil when nothing is removed; spinel returns the receiver in all cases.)

Refs #1216

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
85de02a7d573
Parent
30fec84f4ba5

spinel_analyze.rbmodifiedView file

@@ -6191,6 +6191,16 @@
61916191 end
61926192 end
61936193 end
6194+ # `select!`/`filter!`/`keep_if`/`reject!`/`delete_if` filter in place
6195+ # and return the receiver, keeping its array type.
6196+ if (mname == "select!" || mname == "filter!" || mname == "keep_if" || mname == "reject!" || mname == "delete_if") && @nd_block[nid] >= 0
6197+ if recv >= 0
6198+ rt_fb = infer_type(recv)
6199+ if is_array_type(rt_fb) == 1
6200+ return rt_fb
6201+ end
6202+ end
6203+ end
61946204 if mname == "map"
61956205 if recv >= 0
61966206 # Declare bp inside a scope so infer_type sees the inner element type, not a shadowed outer local.