ref: f7a72a58eb68eed19f00aa722122ff3df3258e43
parent: 688b3b5a20b86796fbd92ca82e3fc80128bb5443
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Jan 3 14:40:31 EST 2015
Grow buffer exponentially when slurping. Growing by 4k each time is /slow/ when mmaping. Dear god that is a dumb idea.
--- a/libstd/slurp.myr
+++ b/libstd/slurp.myr
@@ -11,7 +11,7 @@
const fslurp : (path : fd -> result(byte[:], byte[:]))
;;
-const Bufinc = 4096
+const Bufstart = 4096
const slurp = {path
var fd
@@ -23,12 +23,13 @@
}
const fslurp = {fd
- var n
- var len
+ var len, bufsz
var buf
+ var n
len = 0
- buf = slalloc(Bufinc)
+ bufsz = Bufstart
+ buf = slalloc(bufsz)
while true
n = read(fd, buf[len:])
if n <= 0
@@ -35,7 +36,8 @@
goto done
;;
len += n
- buf = slgrow(buf, len + Bufinc)
+ bufsz *= 2
+ buf = slgrow(buf, bufsz)
;;
:done
-> `Ok buf[:len]