On Mon, Apr 28, 2008 at 10:50 PM, Gwern Branwen <[EMAIL PROTECTED]> wrote:
>  > I think this is a reasonable option.  Why not look (as I think Jason
>  > suggested) in min(4k,len) of the contents? I think 4k is quite a resonable
>  > cutoff, as it's probably at or under a page on all architectures, which
>  > means that most likely it takes no extra IO to read 4k instead of less.  Of
>  > course, this only helps for folks with files larger than 4k, but that
>  > solves problems like your 8g file that is disk-access-dominated.
>
>  OK. I've actually done things a little differently than your suggestion, 
> since I discovered that apparently 'min' isn't any sort of built-in or 
> standard C function. I noticed that the call stack looked like A -> B -> C -> 
> D and E. Since D :: PackedString -> Bool, I just plopped in a 'takePS 4096'.

For cases of big files, another good option would be to add a function

readFromFile :: String -> Int -> IO PackedString

which just reads the first Int bytes of the file.  This could be more
efficient than the simple implementation, which would be:

readFromFile f n = takePS n `fmap` readFile f

David
_______________________________________________
darcs-users mailing list
[email protected]
http://lists.osuosl.org/mailman/listinfo/darcs-users

Reply via email to