Skip to content

Commit

Permalink
Split out strictifyChunk
Browse files Browse the repository at this point in the history
  • Loading branch information
mightybyte committed Sep 28, 2012
1 parent 32c4f89 commit 13b28af
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/Heist/Compiled/Internal.hs
Expand Up @@ -221,12 +221,16 @@ compileTemplate :: Monad n
-> IO [Chunk n]
compileTemplate hs tpath df = do
!chunks <- runSplice nullNode hs $! runDocumentFile tpath df
return $! map strictify chunks
return $! map strictifyChunk chunks
where
-- This gets overwritten in runDocumentFile
nullNode = X.TextNode ""
strictify (Pure b) = Pure $! fromByteString $! toByteString b
strictify c = c


strictifyChunk :: Monad m => Chunk m -> Chunk m
strictifyChunk (Pure b) = Pure $! fromByteString $! toByteString b
strictifyChunk !c = c
{-# INLINE strictifyChunk #-}


------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/Heist/Types.hs
Expand Up @@ -119,6 +119,7 @@ isPureChunk :: Chunk m -> Bool
isPureChunk (Pure _) = True
isPureChunk _ = False


------------------------------------------------------------------------------
-- | Type alias for attribute splices. The function parameter is the value of
-- the bound attribute splice. The return value is a list of attribute
Expand Down
4 changes: 2 additions & 2 deletions test/suite/Benchmark.hs
Expand Up @@ -39,7 +39,7 @@ loadWithCache baseDir = do
main = do
let page = "faq"
pageStr = T.unpack $ decodeUtf8 page
dir = "snap-website"
dir = "snap-website-nocache"
hs <- loadWithCache dir
let !compiledTemplate = fst $! fromJust $! C.renderTemplate hs page
compiledAction = do
Expand All @@ -48,7 +48,7 @@ main = do
out <- compiledAction
B.writeFile (pageStr++".out.compiled."++dir) $ out
putStrLn "Templates loaded"
replicateM_ 10000 $ whnfIO compiledAction
replicateM_ 1000000 $ whnfIO compiledAction
putStrLn "done"

justRender dir = do
Expand Down

0 comments on commit 13b28af

Please sign in to comment.