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 1
2316823168 end
2316923169 end
23170+ # Typed array Array#clear — zero the length (and start
23171+ # for IntArray, which uses a sliding window). Capacity
23172+ # and the backing buffer stay; subsequent pushes refill
23173+ # 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 1
23178+ end
23179+ if rt == "float_array" || rt == "poly_array" || is_ptr_array_type(rt) == 1
23180+ rc = compile_expr_gc_rooted(recv)
23181+ emit(" " + rc + "->len = 0;")
23182+ return 1
23183+ end
23184+ if rt == "str_array"
23185+ rc = compile_expr_gc_rooted(recv)
23186+ # StrArray has an inline-storage optimization: data may
23187+ # point to inline_data (small) or a malloc'd buffer.
23188+ # Either way, zeroing len is a clean reset — the next
23189+ # push refills from index 0.
23190+ emit(" " + rc + "->len = 0;")
23191+ return 1
23192+ end
2317023193 end
2317123194 end
2317223195