on master help sign in
Speedup of factor 4 by switching to the Data.Binary library for serialization.
commitcf789c7ac677b9c13ae6f26d7dda950584a373c8 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateWed 20 Jan 2010, 22:08 (17 years ago) parent98d712f
3 files changed+15−9
hakyll.cabal+2−1 src/Text/Hakyll/Internal/Cache.hs+5−7 src/Text/Hakyll/Page.hs+8−1
hakyll.cabal+2−1
@@ -34,7 +34,8 @@ library
3434 mtl >= 1.1,
3535 old-locale >= 1,
3636 time >= 1,
37− parallel >= 2
37+ parallel >= 2,
38+ binary >= 0.5
3839 exposed-modules: Text.Hakyll
3940 Text.Hakyll.Hakyll
4041 Text.Hakyll.Render
src/Text/Hakyll/Internal/Cache.hs+5−7
@@ -6,19 +6,17 @@ module Text.Hakyll.Internal.Cache
66import Control.Monad.Reader (liftIO)
77import Text.Hakyll.Hakyll (Hakyll)
88import Text.Hakyll.File
9+import Data.Binary
910
10−storeInCache :: (Show a) => a -> FilePath -> Hakyll ()
11+storeInCache :: (Binary a) => a -> FilePath -> Hakyll ()
1112storeInCache value path = do
1213 cachePath <- toCache path
1314 makeDirectories cachePath
14− liftIO $ writeFile cachePath (show value)
15+ liftIO $ encodeFile cachePath value
1516
16−getFromCache :: (Read a) => FilePath -> Hakyll (Maybe a)
17+getFromCache :: (Binary a) => FilePath -> Hakyll (Maybe a)
1718getFromCache path = do
1819 cachePath <- toCache path
1920 valid <- isMoreRecent cachePath [path]
20− if valid then liftIO (getFromCache' cachePath) >>= return . Just
21+ if valid then liftIO (decodeFile cachePath) >>= return . Just
2122 else return Nothing
22− where
23− getFromCache' cachePath = do c <- readFile cachePath
24− return (read c)
src/Text/Hakyll/Page.hs+8−1
@@ -11,12 +11,14 @@ import qualified Data.Map as M
1111import Data.List (isPrefixOf)
1212import Data.Char (isSpace)
1313import Data.Maybe (fromMaybe)
14−import Control.Parallel.Strategies (rdeepseq, ($|))
14+import Control.Monad (liftM)
1515import Control.Monad.Reader (liftIO)
16+import Control.Parallel.Strategies (rdeepseq, ($|))
1617import System.FilePath (takeExtension)
1718import System.IO
1819
1920import Text.Pandoc
21+import Data.Binary
2022
2123import Text.Hakyll.Internal.Cache
2224import Text.Hakyll.Hakyll (Hakyll)
@@ -148,3 +150,8 @@ instance Renderable Page where
148150 getDependencies = (:[]) . getPagePath
149151 getURL = getPageURL
150152 toContext (Page page) = return page
153+
154+-- Make pages serializable.
155+instance Binary Page where
156+ put (Page context) = put $ M.toList context
157+ get = liftM (Page . M.fromList) get