From 56bd1e2d70a7697ea824eafc82a648982b2f19da Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 9 Sep 2021 00:38:16 +0100 Subject: [PATCH] Simplify `strings.write_byte` and `strings.write_bytes` --- core/strings/builder.odin | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/core/strings/builder.odin b/core/strings/builder.odin index b378811bb..607e11c11 100644 --- a/core/strings/builder.odin +++ b/core/strings/builder.odin @@ -128,29 +128,17 @@ builder_space :: proc(b: Builder) -> int { } write_byte :: proc(b: ^Builder, x: byte) -> (n: int) { - if builder_space(b^) > 0 { - append(&b.buf, x) - n += 1 - } - return + n0 := len(b.buf) + append(&b.buf, x) + n1 := len(b.buf) + return n1-n0 } write_bytes :: proc(b: ^Builder, x: []byte) -> (n: int) { - x := x - for len(x) != 0 { - space := builder_space(b^) - if space == 0 { - break // No need to append - } - i := min(space, len(x)) - n += i - append(&b.buf, ..x[:i]) - if len(x) <= i { - break // No more data to append - } - x = x[i:] - } - return + n0 := len(b.buf) + append(&b.buf, ..x) + n1 := len(b.buf) + return n1-n0 } write_rune_builder :: proc(b: ^Builder, r: rune) -> (int, io.Error) {