Skip to content

Commit 6c1001c

Browse files
authored
Merge pull request #546 from robinheghan/use-fnv-hash
Use fnv hash
2 parents 0514283 + 8f4749e commit 6c1001c

File tree

7 files changed

+24
-169
lines changed

7 files changed

+24
-169
lines changed

elm.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@
3030
"elm/core": "1.0.0 <= v < 2.0.0",
3131
"elm/json": "1.0.0 <= v < 2.0.0",
3232
"elm/virtual-dom": "1.0.0 <= v < 2.0.0",
33+
"robinheghan/fnv1a": "1.0.0 <= v < 2.0.0",
3334
"rtfeldman/elm-hex": "1.0.0 <= v < 2.0.0"
3435
},
3536
"test-dependencies": {
3637
"elm-explorations/test": "1.2.2 <= v < 2.0.0"
3738
}
38-
}
39+
}

src/Css/Structure/Hash.elm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ module Css.Structure.Hash exposing (hashDeclarations)
33
import Css.String
44
import Css.Structure exposing (..)
55
import Css.Structure.Output as Output
6-
import Hash exposing (hash)
6+
import FNV1a
77
import String
88

99

1010
hashDeclarations : List Declaration -> Int
1111
hashDeclarations declarations =
12-
List.foldl hashDeclaration Hash.initialSeed declarations
12+
List.foldl hashDeclaration FNV1a.initialSeed declarations
1313

1414

1515
hashDeclaration : Declaration -> Int -> Int
@@ -22,12 +22,12 @@ hashDeclaration decl hash =
2222
let
2323
queryHash =
2424
List.map Output.mediaQueryToString mediaQueries
25-
|> List.foldl Hash.hash hash
25+
|> List.foldl FNV1a.hashWithSeed hash
2626

2727
blockHash =
2828
List.foldl hashStyleBlock queryHash styleBlocks
2929
in
30-
Hash.hash "@media" blockHash
30+
FNV1a.hashWithSeed "@media" blockHash
3131

3232
SupportsRule _ _ ->
3333
hash
@@ -42,7 +42,7 @@ hashDeclaration decl hash =
4242
hash
4343

4444
Keyframes { name, declaration } ->
45-
List.foldl Hash.hash hash [ "@keyframes", name, declaration ]
45+
List.foldl FNV1a.hashWithSeed hash [ "@keyframes", name, declaration ]
4646

4747
Viewport _ ->
4848
hash
@@ -61,4 +61,4 @@ hashStyleBlock (StyleBlock firstSelector otherSelectors properties) hash =
6161
(firstSelector :: otherSelectors)
6262
|> Css.String.mapJoin Output.selectorToString ", "
6363
in
64-
List.foldl Hash.hash hash (selectorStr :: properties)
64+
List.foldl FNV1a.hashWithSeed hash (selectorStr :: properties)

src/ElmCssVendor/Murmur3.elm

Lines changed: 0 additions & 134 deletions
This file was deleted.

src/Hash.elm

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
1-
module Hash exposing (fromString, hash, initialSeed)
1+
module Hash exposing (fromString)
22

3-
import ElmCssVendor.Murmur3 as Murmur3
3+
import FNV1a
44
import Hex
55

66

7-
hash : String -> Int -> Int
8-
hash str seed =
9-
Murmur3.hashString seed str
10-
11-
127
fromString : String -> String
138
fromString str =
14-
str
15-
|> Murmur3.hashString initialSeed
9+
FNV1a.hash str
1610
|> Hex.toString
1711
|> String.cons '_'
18-
19-
20-
initialSeed : Int
21-
initialSeed =
22-
15739

src/VirtualDom/Styled.elm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import Css.Preprocess as Preprocess exposing (Style)
3232
import Css.Preprocess.Resolve as Resolve
3333
import Css.Structure as Structure
3434
import Dict exposing (Dict)
35-
import ElmCssVendor.Murmur3 as Murmur3
3635
import Hex
3736
import Json.Decode
3837
import Json.Encode

tests/Keyframes.elm

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ suite =
3535

3636
output =
3737
"""
38-
@keyframes _a56b5063 {
38+
@keyframes _f8c0e7dc {
3939
0% {background-color:#00FF00;background-size:2px;}
4040
4141
50% {opacity:0;}
@@ -54,12 +54,12 @@ suite =
5454
p {
5555
color:#FF0000;
5656
display:inline;
57-
animation-name:_a56b5063;
57+
animation-name:_f8c0e7dc;
5858
background-color:rgb(11, 11, 11);
5959
}
6060
6161
i {
62-
animation-name:_a56b5063;
62+
animation-name:_f8c0e7dc;
6363
}
6464
"""
6565
in
@@ -97,11 +97,11 @@ suite =
9797

9898
output =
9999
"""
100-
@keyframes _23526425 {
100+
@keyframes _70a5b6a0 {
101101
10% {transform:translate(100px);}
102102
}
103103
104-
@keyframes _a56b5063 {
104+
@keyframes _f8c0e7dc {
105105
0% {background-color:#00FF00;background-size:2px;}
106106
107107
50% {opacity:0;}
@@ -115,14 +115,14 @@ suite =
115115
116116
button {
117117
margin:auto;
118-
animation-name:_23526425;
118+
animation-name:_70a5b6a0;
119119
background-color:#0F0F0F;
120120
}
121121
122122
p {
123123
color:#FF0000;
124124
display:inline;
125-
animation-name:_a56b5063;
125+
animation-name:_f8c0e7dc;
126126
background-color:rgb(11, 11, 11);
127127
}
128128
"""

tests/Styled.elm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,28 +99,28 @@ all =
9999
(\_ ->
100100
Query.fromHtml (toUnstyled <| view "BUY TICKETS")
101101
|> Query.has
102-
[ Selector.text """._3de4d102 {
102+
[ Selector.text """._2e879635 {
103103
background-color:#333333;
104104
padding:20px;
105105
}"""
106-
, Selector.text """._e9904f07 {
106+
, Selector.text """._322e2311 {
107107
margin:12px;
108108
color:rgb(255, 255, 255);
109109
}"""
110-
, Selector.text """._3ac819d0 {
110+
, Selector.text """._c6e22f50 {
111111
display:inline-block;
112112
padding-bottom:12px;
113113
}"""
114-
, Selector.text """._c9b3bf47 {
114+
, Selector.text """._9c310192 {
115115
display:inline-block;
116116
margin-left:150px;
117117
margin-right:80px;
118118
vertical-align:middle;
119119
}"""
120-
, Selector.text """._b9f3f75d {
120+
, Selector.text """._5daeac28 {
121121
background-color:#222222;
122122
}"""
123-
, Selector.text """._33ecd3f8 {
123+
, Selector.text """._36e932ea {
124124
padding:16px;
125125
padding-left:24px;
126126
padding-right:24px;

0 commit comments

Comments
 (0)