commit 1ce64002a02de07e29b395f56c4208c767357f19
parent fddbf7821363eadde0ab44b7e2c933afc803e5c4
Author: Drew DeVault <sir@cmpwn.com>
Date: Sat, 6 Nov 2021 10:19:53 +0100
slice: add slice::trunc
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
3 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib
@@ -862,6 +862,7 @@ gensrcs_strconv() {
slice() {
gen_srcs slice \
reverse.ha \
+ trunc.ha \
void.ha
gen_ssa slice types
}
diff --git a/slice/trunc.ha b/slice/trunc.ha
@@ -0,0 +1,8 @@
+use types;
+
+// Truncates a slice, setting its length to zero without freeing the underlying
+// storage or altering its capacity.
+export fn trunc(sl: *[]void) void = {
+ let sl = sl: *types::slice_repr;
+ sl.length = 0;
+};
diff --git a/stdlib.mk b/stdlib.mk
@@ -1393,6 +1393,7 @@ $(HARECACHE)/path/path-any.ssa: $(stdlib_path_any_srcs) $(stdlib_rt) $(stdlib_st
# slice (+any)
stdlib_slice_any_srcs= \
$(STDLIB)/slice/reverse.ha \
+ $(STDLIB)/slice/trunc.ha \
$(STDLIB)/slice/void.ha
$(HARECACHE)/slice/slice-any.ssa: $(stdlib_slice_any_srcs) $(stdlib_rt) $(stdlib_types_$(PLATFORM))
@@ -3068,6 +3069,7 @@ $(TESTCACHE)/path/path-any.ssa: $(testlib_path_any_srcs) $(testlib_rt) $(testlib
# slice (+any)
testlib_slice_any_srcs= \
$(STDLIB)/slice/reverse.ha \
+ $(STDLIB)/slice/trunc.ha \
$(STDLIB)/slice/void.ha
$(TESTCACHE)/slice/slice-any.ssa: $(testlib_slice_any_srcs) $(testlib_rt) $(testlib_types_$(PLATFORM))