From b615e4a42e4fda85c9132869939e2ad4ffa5e3c3 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sun, 17 May 2026 17:29:49 +0200 Subject: [PATCH] Implemented mem.copy --- lib/mem/copy.q | 11 +++++++++++ lib/strings/concat.q | 11 ++--------- 2 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 lib/mem/copy.q diff --git a/lib/mem/copy.q b/lib/mem/copy.q new file mode 100644 index 0000000..c85aa43 --- /dev/null +++ b/lib/mem/copy.q @@ -0,0 +1,11 @@ +copy(to string, from string) { + len := from.len + + if to.len < len { + len = to.len + } + + loop i := 0..len { + to[i] = from[i] + } +} \ No newline at end of file diff --git a/lib/strings/concat.q b/lib/strings/concat.q index 3f7c537..cba4eb1 100644 --- a/lib/strings/concat.q +++ b/lib/strings/concat.q @@ -2,14 +2,7 @@ import mem concat(a string, b string) -> !string { combined := mem.alloc(a.len + b.len) - - loop i := 0..a.len { - combined[i] = a[i] - } - - loop i := 0..b.len { - combined[a.len+i] = b[i] - } - + mem.copy(combined, a) + mem.copy(combined[a.len..], b) return combined } \ No newline at end of file -- 2.51.2