diff options
author | Ian Lynagh <igloo@earth.li> | 2012-07-14 20:48:42 +0100 |
---|---|---|
committer | Ian Lynagh <igloo@earth.li> | 2012-07-14 20:57:37 +0100 |
commit | 7ae1bec53801069661e249e47ebd6998d6450093 (patch) | |
tree | 3bf00efb097a569173b2c2e9fe1d10347508c6ba /compiler/utils/Binary.hs | |
parent | 18f82197efbc2b930b123032fd7828626c04ee43 (diff) | |
download | haskell-7ae1bec53801069661e249e47ebd6998d6450093.tar.gz |
Implement FastBytes, and use it for MachStr
This is a first step on the way to refactoring the FastString type.
FastBytes currently has no unique, mainly because there isn't currently
a nice way to produce them in Binary.
Also, we don't currently do the "Dictionary" thing with FastBytes in
Binary. I'm not sure whether this is important.
We can change both decisions later, but in the meantime this gets the
refactoring underway.
Diffstat (limited to 'compiler/utils/Binary.hs')
-rw-r--r-- | compiler/utils/Binary.hs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/compiler/utils/Binary.hs b/compiler/utils/Binary.hs index 77bd190fa9..bf24b09b71 100644 --- a/compiler/utils/Binary.hs +++ b/compiler/utils/Binary.hs @@ -725,7 +725,14 @@ type SymbolTable = Array Int Name --------------------------------------------------------- putFS :: BinHandle -> FastString -> IO () -putFS bh (FastString _ l _ buf _) = do +putFS bh fs = putFB bh $ fastStringToFastBytes fs + +getFS :: BinHandle -> IO FastString +getFS bh = do fb <- getFB bh + mkFastStringFastBytes fb + +putFB :: BinHandle -> FastBytes -> IO () +putFB bh (FastBytes l buf) = do put_ bh l withForeignPtr buf $ \ptr -> let @@ -738,19 +745,19 @@ putFS bh (FastString _ l _ buf _) = do go 0 {- -- possible faster version, not quite there yet: -getFS bh@BinMem{} = do +getFB bh@BinMem{} = do (I# l) <- get bh arr <- readIORef (arr_r bh) off <- readFastMutInt (off_r bh) - return $! (mkFastSubStringBA# arr off l) + return $! (mkFastSubBytesBA# arr off l) -} -getFS :: BinHandle -> IO FastString -getFS bh = do +getFB :: BinHandle -> IO FastBytes +getFB bh = do l <- get bh fp <- mallocForeignPtrBytes l withForeignPtr fp $ \ptr -> do let - go n | n == l = mkFastStringForeignPtr ptr fp l + go n | n == l = return $ foreignPtrToFastBytes fp l | otherwise = do b <- getByte bh pokeElemOff ptr n b @@ -758,6 +765,10 @@ getFS bh = do -- go 0 +instance Binary FastBytes where + put_ bh f = putFB bh f + get bh = getFB bh + instance Binary FastString where put_ bh f = case getUserData bh of |