-- ** Construction
mkFastString,
mkFastStringBytes,
+ mkFastStringByteList,
mkFastStringForeignPtr,
mkFastString#,
mkZFastString,
utf8EncodeString ptr str
mkFastStringForeignPtr ptr buf l
+-- | Creates a 'FastString' from a UTF-8 encoded @[Word8]@
+mkFastStringByteList :: [Word8] -> FastString
+mkFastStringByteList str =
+ inlinePerformIO $ do
+ let l = Prelude.length str
+ buf <- mallocForeignPtrBytes l
+ withForeignPtr buf $ \ptr -> do
+ pokeArray (castPtr ptr) str
+ mkFastStringForeignPtr ptr buf l
-- | Creates a Z-encoded 'FastString' from a 'String'
mkZFastString :: String -> FastString
in
go str 0
-#if __GLASGOW_HASKELL__ < 600
-
-mallocForeignPtrBytes :: Int -> IO (ForeignPtr a)
-mallocForeignPtrBytes n = do
- r <- mallocBytes n
- newForeignPtr r (finalizerFree r)
-
-foreign import ccall unsafe "stdlib.h free"
- finalizerFree :: Ptr a -> IO ()
-
-peekCAStringLen = peekCStringLen
-
-#elif __GLASGOW_HASKELL__ <= 602
-
+#if __GLASGOW_HASKELL__ <= 602
peekCAStringLen = peekCStringLen
-
#endif
\end{code}