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 12228822288
end2228922289
end22290+
# Typed array Array#clear — zero the length (and start22291+
# for IntArray, which uses a sliding window). Capacity22292+
# and the backing buffer stay; subsequent pushes refill22293+
# 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 122298+
end22299+
if rt == "float_array" || rt == "poly_array" || is_ptr_array_type(rt) == 122300+
rc = compile_expr_gc_rooted(recv)22301+
emit(" " + rc + "->len = 0;")22302+
return 122303+
end22304+
if rt == "str_array"22305+
rc = compile_expr_gc_rooted(recv)22306+
# StrArray has an inline-storage optimization: data may22307+
# point to inline_data (small) or a malloc'd buffer.22308+
# Either way, zeroing len is a clean reset — the next22309+
# push refills from index 0.22310+
emit(" " + rc + "->len = 0;")22311+
return 122312+
end2229022313
end2229122314
end2229222315
test/array_clear_typed.rbaddedView file
Loading diff…