From b24d4208e42ee25d3cc3da713b75590eadedf94f Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Sun, 19 Apr 2020 10:58:16 +1200 Subject: [PATCH] Optimize: use HashMap.Lazy for cascade. --- src/Data/CSS/Style/Cascade.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Data/CSS/Style/Cascade.hs b/src/Data/CSS/Style/Cascade.hs index 698da67..68a0c32 100644 --- a/src/Data/CSS/Style/Cascade.hs +++ b/src/Data/CSS/Style/Cascade.hs @@ -12,6 +12,7 @@ import Data.CSS.Syntax.Tokens -- TODO do performance tests to decide beside between strict/lazy, -- or is another Map implementation better? import Data.HashMap.Strict +import qualified Data.HashMap.Lazy as HML import Data.Text (unpack, pack, isPrefixOf) -- | Defines how to parse CSS properties into an output "style" format. @@ -63,12 +64,12 @@ query self el = Prelude.foldr yield empty $ lookupRules self el -- parsed to a value of the same `PropertyParser` type passed in & inheriting from it. cascade :: PropertyParser p => [StyleRule'] -> Props -> p -> p cascade styles overrides base = - construct base $ toList $ cascadeRules (getVars base ++ overrides) styles + construct base $ HML.toList $ cascadeRules (getVars base ++ overrides) styles cascadeRules :: Props -> [StyleRule'] -> HashMap Text [Token] cascadeRules overrides rules = cascadeProperties overrides $ concat $ Prelude.map properties rules cascadeProperties :: Props -> Props -> HashMap Text [Token] -cascadeProperties overrides props = fromList (props ++ overrides) +cascadeProperties overrides props = HML.fromList (props ++ overrides) construct :: PropertyParser p => p -> Props -> p construct base props = dispatch base child props -- 2.30.2