ref: d12aa33d9b7f5c00fc0995cc0b31526ab2dbf17e
parent: d77c63a440b6d665f666d8fc0b45811f75eae6e8
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]