summaryrefslogtreecommitdiff
path: root/lib/std/slurp.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-01-20 22:17:52 -0800
committerOri Bernstein <ori@eigenstate.org>2016-01-20 22:26:18 -0800
commit83c62e5ed5a9d1cf16d418e7b54391074bf38918 (patch)
tree8cd33717548f96139408836228deb8474f5740da /lib/std/slurp.myr
parentc694d9a9c3f8c78837cf3bcbbe11fb19d04c204d (diff)
downloadmc-83c62e5ed5a9d1cf16d418e7b54391074bf38918.tar.gz
Don't grow the buffer for every read.
Some things, like pipe buffers, will eventually cap out at a certain size. Only grow the buffer if we couldn't do another read twice the size of the last one.
Diffstat (limited to 'lib/std/slurp.myr')
-rw-r--r--lib/std/slurp.myr6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/std/slurp.myr b/lib/std/slurp.myr
index 576c39e..e644a87 100644
--- a/lib/std/slurp.myr
+++ b/lib/std/slurp.myr
@@ -37,8 +37,10 @@ const fslurp = {fd
-> `Ok buf[:len]
| `Ok n:
len += n
- bufsz *= 2
- buf = slgrow(buf, bufsz)
+ if len + 2*n >= bufsz
+ bufsz *= 2
+ buf = slgrow(buf, bufsz)
+ ;;
| `Fail e:
-> `Fail e
;;