shithub: MicroHs

Download patch

ref: d86f4ae08fd96bade8c7a333356cec60a16b04bf
parent: dd9af73109c039fca467fae8849742aded49ed6f
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Sun Nov 26 06:20:52 EST 2023

Better writeFileFast

--- a/lib/Foreign/C/String.hs
+++ b/lib/Foreign/C/String.hs
@@ -1,7 +1,8 @@
 module Foreign.C.String(
   CChar, CString,
-  newCAString, withCAString,
+  newCAString, newCAStringLen,
   peekCAString, peekCAStringLen,
+  withCAString,
   ) where
 import Primitives
 import Data.Char_Type
--- a/lib/System/IO.hs
+++ b/lib/System/IO.hs
@@ -161,12 +161,10 @@
   hClose h
 
 -- Faster, but uses a lot more C memory.
--- It also holds not GC friendly.
 writeFileFast :: FilePath -> String -> IO ()
 writeFileFast p s = do
   h <- openFile p WriteMode
-  cs <- newCAString s
-  let l = length s
+  (cs, l) <- newCAStringLen s
   n <- c_fwrite cs 1 l h
   free cs
   hClose h
--