diff options
author | Ian Lynagh <ian@well-typed.com> | 2012-12-12 17:12:13 +0000 |
---|---|---|
committer | Ian Lynagh <ian@well-typed.com> | 2012-12-12 21:33:19 +0000 |
commit | d5b5d48881b3adbf3bd5e177ee6ef506e589b882 (patch) | |
tree | ea99b95522a460cd934cdf2a1f09dd6359bb654c /compiler/utils/BufWrite.hs | |
parent | bd8f7fc56b84369f4e820263c0bcdc85760de6d4 (diff) | |
download | haskell-d5b5d48881b3adbf3bd5e177ee6ef506e589b882.tar.gz |
Use ByteString rather than FastBytes inside FastZString
Slow nofib Compile Times difference looks like just noise:
-1 s.d. -2.9%
+1 s.d. +2.9%
Average -0.1%
Diffstat (limited to 'compiler/utils/BufWrite.hs')
-rw-r--r-- | compiler/utils/BufWrite.hs | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/compiler/utils/BufWrite.hs b/compiler/utils/BufWrite.hs index ea5cee01db..5ad165dcd8 100644 --- a/compiler/utils/BufWrite.hs +++ b/compiler/utils/BufWrite.hs @@ -35,8 +35,11 @@ import FastTypes import FastMutInt import Control.Monad ( when ) +import Data.ByteString (ByteString) +import qualified Data.ByteString.Unsafe as BS import Data.Char ( ord ) import Foreign +import Foreign.C.String import System.IO -- ----------------------------------------------------------------------------- @@ -88,21 +91,27 @@ bPutFS :: BufHandle -> FastString -> IO () bPutFS b fs = bPutFB b $ fastStringToFastBytes fs bPutFZS :: BufHandle -> FastZString -> IO () -bPutFZS b fs = bPutFB b $ fastZStringToFastBytes fs +bPutFZS b fs = bPutBS b $ fastZStringToByteString fs bPutFB :: BufHandle -> FastBytes -> IO () -bPutFB b@(BufHandle buf r hdl) fb@(FastBytes len fp) = - withForeignPtr fp $ \ptr -> do +bPutFB b (FastBytes len fp) = + withForeignPtr fp $ \ptr -> bPutCStringLen b (castPtr ptr, len) + +bPutBS :: BufHandle -> ByteString -> IO () +bPutBS b bs = BS.unsafeUseAsCStringLen bs $ bPutCStringLen b + +bPutCStringLen :: BufHandle -> CStringLen -> IO () +bPutCStringLen b@(BufHandle buf r hdl) cstr@(ptr, len) = do i <- readFastMutInt r if (i + len) >= buf_size - then do hPutBuf hdl buf i - writeFastMutInt r 0 - if (len >= buf_size) - then hPutBuf hdl ptr len - else bPutFB b fb - else do - copyBytes (buf `plusPtr` i) ptr len - writeFastMutInt r (i+len) + then do hPutBuf hdl buf i + writeFastMutInt r 0 + if (len >= buf_size) + then hPutBuf hdl ptr len + else bPutCStringLen b cstr + else do + copyBytes (buf `plusPtr` i) ptr len + writeFastMutInt r (i + len) bPutLitString :: BufHandle -> LitString -> FastInt -> IO () bPutLitString b@(BufHandle buf r hdl) a len_ = a `seq` do |