~alcinnz/haskell-stylist

b24d4208e42ee25d3cc3da713b75590eadedf94f — Adrian Cochrane 4 years ago dc78097
Optimize: use HashMap.Lazy for cascade.
1 files changed, 3 insertions(+), 2 deletions(-)

M src/Data/CSS/Style/Cascade.hs
M src/Data/CSS/Style/Cascade.hs => src/Data/CSS/Style/Cascade.hs +3 -2
@@ 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