From 83c62e5ed5a9d1cf16d418e7b54391074bf38918 Mon Sep 17 00:00:00 2001 From: Ori Bernstein Date: Wed, 20 Jan 2016 22:17:52 -0800 Subject: 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. --- lib/std/slurp.myr | 6 ++++-- 1 file 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 ;; -- cgit v1.1