summaryrefslogtreecommitdiff
path: root/lib/bio
diff options
context:
space:
mode:
authorOri Bernstein <ori@markovcorp.com>2018-03-10 18:16:21 -0800
committerOri Bernstein <ori@markovcorp.com>2018-03-10 18:16:21 -0800
commitdbf04d054d0fc04385c766ced8e0f3b3edd120e8 (patch)
treed51cf08fccb6a5c905217a6de30733458b5d84a5 /lib/bio
parente65d5c4019e76430398e4ebc1cb734f1efea3b14 (diff)
downloadmc-dbf04d054d0fc04385c766ced8e0f3b3edd120e8.tar.gz
Clean up readinto.
Diffstat (limited to 'lib/bio')
-rw-r--r--lib/bio/bio.myr19
1 files changed, 8 insertions, 11 deletions
diff --git a/lib/bio/bio.myr b/lib/bio/bio.myr
index 483662a..b76f985 100644
--- a/lib/bio/bio.myr
+++ b/lib/bio/bio.myr
@@ -365,7 +365,7 @@ const readln = {f
/* get at least delimiter count of characters */
match ensureread(f, 1)
| `std.Err `Eof:
- ret = readinto(f, ret, f.rend - f.rstart)
+ readinto(f, &ret, f.rend - f.rstart)
if ret.len > 0
-> `std.Ok ret
else
@@ -378,7 +378,7 @@ const readln = {f
for var i = f.rstart; i < f.rend; i++
c = (f.rbuf[i] : char)
if c == '\r' || c == '\n'
- ret = readinto(f, ret, i - f.rstart)
+ readinto(f, &ret, i - f.rstart)
f.rstart++
/* if we have '\r', we can get '\r\n'. */
if c == '\r' && unwrapc(peekc(f), -1) == '\n'
@@ -388,7 +388,7 @@ const readln = {f
;;
:nextitergetln
;;
- ret = readinto(f, ret, f.rend - f.rstart)
+ readinto(f, &ret, f.rend - f.rstart)
;;
std.die("unreachable")
}
@@ -409,7 +409,7 @@ const readdelim = {f, delim, drop
match ensureread(f, 1)
| `std.Err `Eof:
if !drop
- ret = readinto(f, ret, f.rend - f.rstart)
+ readinto(f, &ret, f.rend - f.rstart)
else
f.rstart += f.rend - f.rstart
;;
@@ -429,7 +429,7 @@ const readdelim = {f, delim, drop
;;
;;
if !drop
- ret = readinto(f, ret, i - f.rstart)
+ readinto(f, &ret, i - f.rstart)
else
f.rstart += i - f.rstart
;;
@@ -439,7 +439,7 @@ const readdelim = {f, delim, drop
:nextiterread
;;
if !drop
- ret = readinto(f, ret, f.rend - f.rstart)
+ readinto(f, &ret, f.rend - f.rstart)
else
f.rstart += f.rend - f.rstart
;;
@@ -476,13 +476,10 @@ const putv = {f, fmt, ap
reads n bytes from the read buffer onto the heap-allocated slice
provided.
*/
-const readinto = {f, buf, n
- var ret
-
+const readinto = {f, bufp, n
std.assert(f.rstart + n <= f.rend, "Reading too much from buffer")
- ret = std.sljoin(&buf, f.rbuf[f.rstart:f.rstart + n])
+ std.sljoin(bufp, f.rbuf[f.rstart:f.rstart + n])
f.rstart += n
- -> ret
}
/* makes sure we can bufferedly write at least n bytes */