Commit a2066642
a2066642ba48Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
Merge pull request #189 from mame/pr/array-clear-typed
feat(codegen): Array#clear for typed arrays
Details
- Commit
- a2066642ba48
- Parent
- 7a38b3751353
- Merge parent
- 2a3eabde557c
spinel_codegen.rbmodifiedView file
@@ -23167,6 +23167,29 @@
2316723167
return 12316823168
end2316923169
end23170+
# Typed array Array#clear — zero the length (and start23171+
# for IntArray, which uses a sliding window). Capacity23172+
# and the backing buffer stay; subsequent pushes refill23173+
# the slots from index 0.23174+
if rt == "int_array" || rt == "sym_array"23175+
rc = compile_expr_gc_rooted(recv)23176+
emit(" " + rc + "->len = 0; " + rc + "->start = 0;")23177+
return 123178+
end23179+
if rt == "float_array" || rt == "poly_array" || is_ptr_array_type(rt) == 123180+
rc = compile_expr_gc_rooted(recv)23181+
emit(" " + rc + "->len = 0;")23182+
return 123183+
end23184+
if rt == "str_array"23185+
rc = compile_expr_gc_rooted(recv)23186+
# StrArray has an inline-storage optimization: data may23187+
# point to inline_data (small) or a malloc'd buffer.23188+
# Either way, zeroing len is a clean reset — the next23189+
# push refills from index 0.23190+
emit(" " + rc + "->len = 0;")23191+
return 123192+
end2317023193
end2317123194
end2317223195
test/array_clear_typed.rbaddedView file
Loading diff…