hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit cbc752a6d8afac44229b7701fb197f86c1aad562
parent 8e4c715b79d707e7b9a9782227211715a0a6ccbb
Author: Drew DeVault <sir@cmpwn.com>
Date:   Wed, 28 Apr 2021 11:44:01 -0400

bufio: utilize insert where appropriate

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mbufio/buffered.ha | 8+-------
Mbufio/memstream.ha | 13+------------
2 files changed, 2 insertions(+), 19 deletions(-)

diff --git a/bufio/buffered.ha b/bufio/buffered.ha @@ -118,13 +118,7 @@ export fn unreadrune(s: *io::stream, rn: rune) void = { assert(isbuffered(s), "bufio: unread used on non-buffered stream"); let s = s: *bufstream; const buf = utf8::encoderune(rn); - - // TODO: Insert - let new: []u8 = alloc([], len(s.unread) + len(buf)); - append(new, buf...); - append(new, s.unread...); - free(s.unread); - s.unread = new; + insert(s.unread[0], buf...); }; fn buffered_close(s: *io::stream) void = { diff --git a/bufio/memstream.ha b/bufio/memstream.ha @@ -84,18 +84,7 @@ export fn dynamic_from(in: []u8, mode: io::mode) *io::stream = { fn dynamic_write(s: *io::stream, buf: const []u8) (size | io::error) = { let s = s: *memstream; - if (s.pos == len(s.buf)) { - append(s.buf, buf...); - } else { - // TODO: Insert - let new: []u8 = alloc([], len(s.buf) + len(buf)); - append(new, s.buf[..s.pos]...); - append(new, buf[..]...); - append(new, s.buf[s.pos..]...); - free(s.buf); - s.buf = new; - }; - + insert(s.buf[s.pos], buf...); s.pos += len(buf); return len(buf); };