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
end61926192
end61936193
end6194+
# `select!`/`filter!`/`keep_if`/`reject!`/`delete_if` filter in place6195+
# 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] >= 06197+
if recv >= 06198+
rt_fb = infer_type(recv)6199+
if is_array_type(rt_fb) == 16200+
return rt_fb6201+
end6202+
end6203+
end61946204
if mname == "map"61956205
if recv >= 061966206
# Declare bp inside a scope so infer_type sees the inner element type, not a shadowed outer local.spinel_codegen.rbmodifiedView file
Loading diff…
test/array_select_bang.rbaddedView file
Loading diff…
test/array_select_bang.rb.expectedaddedView file
Loading diff…