Commit 05cab298
05cab2985beaMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
codegen: Array#uniq! dispatched on int_array via replace + uniq
Mutate-in-place: sp_IntArray_uniq returns a fresh array; copy its contents back via sp_IntArray_replace so the receiver shows the deduped result. Return the receiver (CRuby returns self on mutation, nil otherwise; the typed int_array can't carry nil so we always return self in the subset).
Fixes #989
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 05cab2985bea
- Parent
- 6fe14d87f99f
spinel_codegen.rbmodifiedView file
@@ -22278,6 +22278,14 @@
2227822278
if mname == "uniq"2227922279
return "sp_IntArray_uniq(" + rc + ")"2228022280
end22281+
if mname == "uniq!"22282+
# Mutate in place. sp_IntArray_uniq returns a fresh array; copy22283+
# its contents back. The return is the (now-deduped) receiver,22284+
# matching CRuby's "returns self when something was removed,22285+
# nil otherwise" only in the truthy case — we always return self22286+
# since the typed int_array can't carry nil.22287+
return "(sp_IntArray_replace(" + rc + ", sp_IntArray_uniq(" + rc + ")), " + rc + ")"22288+
end2228122289
if mname == "join"2228222290
jarg = compile_arg0(nid)2228322291
if jarg == "0"test/int_array_uniq_bang.rbaddedView file
Loading diff…
test/int_array_uniq_bang.rb.expectedaddedView file
Loading diff…