aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-09-09 00:38:16 +0100
committergingerBill <bill@gingerbill.org>2021-09-09 00:38:16 +0100
commit56bd1e2d70a7697ea824eafc82a648982b2f19da (patch)
tree432d503898de2e64c5cd66469f369e11e83a712f
parenta70ecdba6eb2203db6fc6ff13db89f61d15e07f3 (diff)
Simplify `strings.write_byte` and `strings.write_bytes`
-rw-r--r--core/strings/builder.odin28
1 files 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) {