Skip to content

Commit 37a337b

Browse files
committed
Optimize comparisons to chars
1 parent ee59b9f commit 37a337b

File tree

4 files changed

+77
-10
lines changed

4 files changed

+77
-10
lines changed

src/Elm/Parser/Comments.elm

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@ singleLineComment : ParserFast.Parser (Node String)
1010
singleLineComment =
1111
ParserFast.symbolFollowedBy "--"
1212
(ParserFast.whileMapWithRange
13-
(\c -> c /= '\u{000D}' && c /= '\n' && not (Char.Extra.isUtf16Surrogate c))
13+
(\c ->
14+
case c of
15+
'\u{000D}' ->
16+
False
17+
18+
'\n' ->
19+
False
20+
21+
_ ->
22+
not (Char.Extra.isUtf16Surrogate c)
23+
)
1424
(\range content ->
1525
Node
1626
{ start = { row = range.start.row, column = range.start.column - 2 }

src/Elm/Parser/Expose.elm

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,34 @@ infixExpose =
7979
)
8080
(ParserFast.symbolFollowedBy "("
8181
(ParserFast.ifFollowedByWhileWithoutLinebreak
82-
(\c -> c /= ')' && c /= '\n' && c /= ' ')
83-
(\c -> c /= ')' && c /= '\n' && c /= ' ')
82+
(\c ->
83+
case c of
84+
')' ->
85+
False
86+
87+
'\n' ->
88+
False
89+
90+
' ' ->
91+
False
92+
93+
_ ->
94+
True
95+
)
96+
(\c ->
97+
case c of
98+
')' ->
99+
False
100+
101+
'\n' ->
102+
False
103+
104+
' ' ->
105+
False
106+
107+
_ ->
108+
True
109+
)
84110
)
85111
)
86112
Tokens.parensEnd

src/Elm/Parser/Tokens.elm

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,19 @@ singleQuotedStringLiteralAfterDoubleQuote =
243243
ParserFast.loopUntil (ParserFast.symbol "\"" ())
244244
(ParserFast.oneOf2
245245
(ParserFast.symbolFollowedBy "\\" (escapedCharValueMap String.fromChar))
246-
(ParserFast.whileWithoutLinebreak (\c -> c /= '"' && c /= '\\' && not (Char.Extra.isUtf16Surrogate c)))
246+
(ParserFast.whileWithoutLinebreak
247+
(\c ->
248+
case c of
249+
'"' ->
250+
False
251+
252+
'\\' ->
253+
False
254+
255+
_ ->
256+
not (Char.Extra.isUtf16Surrogate c)
257+
)
258+
)
247259
)
248260
""
249261
(\extension soFar ->
@@ -258,7 +270,19 @@ tripleQuotedStringLiteralOfterTripleDoubleQuote =
258270
(ParserFast.oneOf3
259271
(ParserFast.symbol "\"" "\"")
260272
(ParserFast.symbolFollowedBy "\\" (escapedCharValueMap String.fromChar))
261-
(ParserFast.while (\c -> c /= '"' && c /= '\\' && not (Char.Extra.isUtf16Surrogate c)))
273+
(ParserFast.while
274+
(\c ->
275+
case c of
276+
'"' ->
277+
False
278+
279+
'\\' ->
280+
False
281+
282+
_ ->
283+
not (Char.Extra.isUtf16Surrogate c)
284+
)
285+
)
262286
)
263287
""
264288
(\extension soFar ->

src/Elm/Writer.elm

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -572,13 +572,20 @@ writeChar c =
572572
let
573573
escape : String
574574
escape =
575-
if c == '\t' || c == '\'' || c == '\\' then
576-
"\\"
575+
case c of
576+
'\t' ->
577+
"'\\"
577578

578-
else
579-
""
579+
'\'' ->
580+
"'\\"
581+
582+
'\\' ->
583+
"'\\"
584+
585+
_ ->
586+
"'"
580587
in
581-
string ("'" ++ escape ++ String.fromChar c ++ "'")
588+
string (escape ++ String.fromChar c ++ "'")
582589

583590

584591
{-| Write a pattern

0 commit comments

Comments
 (0)