commit a43f1f8618c6fa4ca5fc07bb20cf09b6dfe748bc
parent cbcd1bd0fd3cadb976df90778ff0d3194939e296
Author: Drew DeVault <sir@cmpwn.com>
Date: Mon, 22 Nov 2021 09:03:09 +0100
all: drop bytes::copy in favor of slice assignment
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
5 files changed, 2 insertions(+), 20 deletions(-)
diff --git a/bytes/copy.ha b/bytes/copy.ha
@@ -1,15 +0,0 @@
-// Copies bytes from "src" to "dest". "dest" must have the same length as "src".
-export fn copy(dest: []u8, src: []u8) void = {
- assert(len(dest) == len(src),
- "Destination slice must have same length as source slice");
- for (let i = 0z; i < len(dest); i += 1) {
- dest[i] = src[i];
- };
-};
-
-@test fn copy() void = {
- let a: [4]u8 = [1, 3, 3, 7];
- let b: [4]u8 = [0...];
- copy(b[..], a[..]);
- assert(equal(a, b));
-};
diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib
@@ -160,7 +160,6 @@ bufio() {
bytes() {
gen_srcs bytes \
contains.ha \
- copy.ha \
equal.ha \
index.ha \
reverse.ha \
diff --git a/stdlib.mk b/stdlib.mk
@@ -624,7 +624,6 @@ $(HARECACHE)/bufio/bufio-any.ssa: $(stdlib_bufio_any_srcs) $(stdlib_rt) $(stdlib
# bytes (+any)
stdlib_bytes_any_srcs= \
$(STDLIB)/bytes/contains.ha \
- $(STDLIB)/bytes/copy.ha \
$(STDLIB)/bytes/equal.ha \
$(STDLIB)/bytes/index.ha \
$(STDLIB)/bytes/reverse.ha \
@@ -2343,7 +2342,6 @@ $(TESTCACHE)/bufio/bufio-any.ssa: $(testlib_bufio_any_srcs) $(testlib_rt) $(test
# bytes (+any)
testlib_bytes_any_srcs= \
$(STDLIB)/bytes/contains.ha \
- $(STDLIB)/bytes/copy.ha \
$(STDLIB)/bytes/equal.ha \
$(STDLIB)/bytes/index.ha \
$(STDLIB)/bytes/reverse.ha \
diff --git a/strconv/itos.ha b/strconv/itos.ha
@@ -19,7 +19,7 @@ export fn i64tosb(i: i64, b: base) const str = {
let u = strings::toutf8(u64tosb((-i): u64, b));
assert(len(u) < len(buf));
- bytes::copy(buf[1..len(u) + 1], u);
+ buf[1..len(u) + 1] = u[..];
s.length += len(u);
return *(&s: *str);
diff --git a/strings/dup.ha b/strings/dup.ha
@@ -17,7 +17,7 @@ export fn dup(s: const str) str = {
case v: *void =>
yield v;
};
- bytes::copy(buf[..in.length + 1z], id[..in.length + 1]);
+ buf[..in.length + 1z] = id[..in.length + 1];
let out = types::string {
data = buf,
length = in.length,