From 13b28afca48c8cb2c1ce08ae1b381c07076ec414 Mon Sep 17 00:00:00 2001 From: Mighty Byte Date: Thu, 27 Sep 2012 20:05:34 -0400 Subject: [PATCH] Split out strictifyChunk --- src/Heist/Compiled/Internal.hs | 10 +++++++--- src/Heist/Types.hs | 1 + test/suite/Benchmark.hs | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Heist/Compiled/Internal.hs b/src/Heist/Compiled/Internal.hs index 0563df6..7d95638 100644 --- a/src/Heist/Compiled/Internal.hs +++ b/src/Heist/Compiled/Internal.hs @@ -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 #-} ------------------------------------------------------------------------------ diff --git a/src/Heist/Types.hs b/src/Heist/Types.hs index b2a3a67..d3a2fb7 100644 --- a/src/Heist/Types.hs +++ b/src/Heist/Types.hs @@ -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 diff --git a/test/suite/Benchmark.hs b/test/suite/Benchmark.hs index 78385f4..56fc1ec 100644 --- a/test/suite/Benchmark.hs +++ b/test/suite/Benchmark.hs @@ -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 @@ -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