Skip to content

Commit 14268c6

Browse files
author
Richard Feldman
committed
Use type alias for Property
This will reduce allocations until we have automatic unboxing of single-constructor union types. At that point, this can be reverted with no runtime downside!
1 parent 4308234 commit 14268c6

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

src/Css.elm

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ Other notes:
10821082
getOverloadedProperty : String -> String -> Style -> Style
10831083
getOverloadedProperty functionName desiredKey style =
10841084
case style of
1085-
Preprocess.AppendProperty (Property str) ->
1085+
Preprocess.AppendProperty str ->
10861086
let
10871087
key =
10881088
String.split ":" str
@@ -1775,15 +1775,15 @@ declaration.
17751775
-}
17761776
important : Style -> Style
17771777
important =
1778-
Preprocess.mapLastProperty (\(Property str) -> Property (makeImportant str))
1778+
Preprocess.mapLastProperty makeImportant
17791779

17801780

1781-
makeImportant : String -> String
1782-
makeImportant value =
1783-
if String.endsWith " !important" (String.toLower value) then
1784-
value
1781+
makeImportant : Property -> Property
1782+
makeImportant str =
1783+
if String.endsWith " !important" (String.toLower str) then
1784+
str
17851785
else
1786-
value ++ " !important"
1786+
str ++ " !important"
17871787

17881788

17891789
{-| A [`ColorValue`](#ColorValue) that does not have `red`, `green`, or `blue`
@@ -7758,7 +7758,7 @@ batch =
77587758
-}
77597759
property : String -> String -> Style
77607760
property key value =
7761-
Property (key ++ ":" ++ value)
7761+
(key ++ ":" ++ value)
77627762
|> Preprocess.AppendProperty
77637763

77647764

src/Css/Preprocess.elm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Css.Preprocess exposing (..)
44
the data structures found in this module.
55
-}
66

7-
import Css.Structure as Structure exposing (MediaQuery, Property(Property), concatMapLast, mapLast)
7+
import Css.Structure as Structure exposing (MediaQuery, Property, concatMapLast, mapLast)
88

99

1010
stylesheet : List Snippet -> Stylesheet
@@ -135,7 +135,7 @@ toPropertyStrings styles =
135135
[] ->
136136
[]
137137

138-
(AppendProperty (Property str)) :: rest ->
138+
(AppendProperty str) :: rest ->
139139
str :: toPropertyStrings rest
140140

141141
(ApplyStyles styles) :: rest ->

src/Css/Structure.elm

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ type alias Number compatible =
1717

1818

1919
{-| A property consisting of a key:value string.
20+
21+
Ideally, this would be `type Property = Property String` - but in order to
22+
reduce allocations, we're doing it as a `type alias` until union types with
23+
one constructor get unboxed automatically.
24+
2025
-}
21-
type Property
22-
= Property String
26+
type alias Property =
27+
String
2328

2429

2530
{-| A stylesheet. Since they follow such specific rules, the following at-rules

src/Css/Structure/Output.elm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ combinatorToString combinator =
229229

230230

231231
emitProperty : Property -> String
232-
emitProperty (Property str) =
232+
emitProperty str =
233233
str ++ ";"
234234

235235

0 commit comments

Comments
 (0)