diff options
author | Andrew Miller <ak.miller@auckland.ac.nz> | 2012-08-08 09:10:18 +1200 |
---|---|---|
committer | Andrew Miller <ak.miller@auckland.ac.nz> | 2012-08-08 09:10:18 +1200 |
commit | 0b7b846a283e4f101c8404f760b65a523e64cf51 (patch) | |
tree | 3fd8ba8db6999994ec10bfe497a04a80e832cd83 /src/Hakyll/Core/Resource | |
parent | 961af33e82e3f40c39b500f93adb828ad77ab2a1 (diff) | |
download | hakyll-0b7b846a283e4f101c8404f760b65a523e64cf51.tar.gz |
Make Resource Provider keep list of files in a set, rather than as a list, and
use Data.Set.member rather than Prelude.elem to test whether a resource exists.
On the site I'm currently working on (where there are ~1000 resources) this
makes hakyll about 25% faster.
Diffstat (limited to 'src/Hakyll/Core/Resource')
-rw-r--r-- | src/Hakyll/Core/Resource/Provider.hs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/Hakyll/Core/Resource/Provider.hs b/src/Hakyll/Core/Resource/Provider.hs index d91c374..14848a8 100644 --- a/src/Hakyll/Core/Resource/Provider.hs +++ b/src/Hakyll/Core/Resource/Provider.hs @@ -12,6 +12,7 @@ -- module Hakyll.Core.Resource.Provider ( ResourceProvider (..) + , resourceList , makeResourceProvider , resourceExists , resourceDigest @@ -22,6 +23,7 @@ import Control.Applicative ((<$>)) import Control.Concurrent (MVar, readMVar, modifyMVar_, newMVar) import Data.Map (Map) import qualified Data.Map as M +import qualified Data.Set as S import Data.Time (UTCTime) import qualified Crypto.Hash.MD5 as MD5 @@ -35,7 +37,7 @@ import Hakyll.Core.Resource -- data ResourceProvider = ResourceProvider { -- | A list of all resources this provider is able to provide - resourceList :: [Resource] + resourceSet :: S.Set Resource , -- | Retrieve a certain resource as string resourceString :: Resource -> IO String , -- | Retrieve a certain resource as lazy bytestring @@ -53,12 +55,16 @@ makeResourceProvider :: [Resource] -- ^ Resource list -> (Resource -> IO LB.ByteString) -- ^ ByteString reader -> (Resource -> IO UTCTime) -- ^ Time checker -> IO ResourceProvider -- ^ Resulting provider -makeResourceProvider l s b t = ResourceProvider l s b t <$> newMVar M.empty +makeResourceProvider l s b t = ResourceProvider (S.fromList l) s b t <$> newMVar M.empty + +-- | Get the list of all resources +resourceList :: ResourceProvider -> [Resource] +resourceList = S.toList . resourceSet -- | Check if a given identifier has a resource -- resourceExists :: ResourceProvider -> Resource -> Bool -resourceExists provider = flip elem $ resourceList provider +resourceExists provider = flip S.member $ resourceSet provider -- | Retrieve a digest for a given resource -- |