Commit 2a3eabde

2a3eabde557cMerged

Yusuke Endoh <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified

Description

feat(codegen): Array#clear for typed arrays

Extend the existing string clear() to also handle typed arrays: zero len (and start for IntArray/SymArray, which use a sliding window). Capacity and the backing buffer stay; later pushes refill from index 0. Previously arr.clear on a typed array fell through the dispatcher and was a silent no-op.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
2a3eabde557c
Parent
78de785dc7bf

spinel_codegen.rbmodifiedView file

@@ -22287,6 +22287,29 @@
2228722287 return 1
2228822288 end
2228922289 end
22290+ # Typed array Array#clear — zero the length (and start
22291+ # for IntArray, which uses a sliding window). Capacity
22292+ # and the backing buffer stay; subsequent pushes refill
22293+ # the slots from index 0.
22294+ if rt == "int_array" || rt == "sym_array"
22295+ rc = compile_expr_gc_rooted(recv)
22296+ emit(" " + rc + "->len = 0; " + rc + "->start = 0;")
22297+ return 1
22298+ end
22299+ if rt == "float_array" || rt == "poly_array" || is_ptr_array_type(rt) == 1
22300+ rc = compile_expr_gc_rooted(recv)
22301+ emit(" " + rc + "->len = 0;")
22302+ return 1
22303+ end
22304+ if rt == "str_array"
22305+ rc = compile_expr_gc_rooted(recv)
22306+ # StrArray has an inline-storage optimization: data may
22307+ # point to inline_data (small) or a malloc'd buffer.
22308+ # Either way, zeroing len is a clean reset — the next
22309+ # push refills from index 0.
22310+ emit(" " + rc + "->len = 0;")
22311+ return 1
22312+ end
2229022313 end
2229122314 end
2229222315