Skip to content

Commit 110aebd

Browse files
committed
Fix performance of Compiler.Json.Encode.escape
1 parent 85c9c83 commit 110aebd

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

src/Compiler/Json/Encode.elm

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -177,31 +177,26 @@ chars chrs =
177177

178178
escape : String -> String
179179
escape chrs =
180-
case String.toList chrs of
181-
[] ->
182-
""
183-
184-
c :: cs ->
185-
let
186-
escapedChar : String
187-
escapedChar =
188-
case c of
189-
'\u{000D}' ->
190-
"\\r"
191-
192-
'\n' ->
193-
"\\n"
194-
195-
'"' ->
196-
"\\\""
197-
198-
'\\' ->
199-
"\\\\"
200-
201-
_ ->
202-
String.fromChar c
203-
in
204-
escapedChar ++ escape (String.fromList cs)
180+
String.toList chrs
181+
|> List.map
182+
(\c ->
183+
case c of
184+
'\u{000D}' ->
185+
"\\r"
186+
187+
'\n' ->
188+
"\\n"
189+
190+
'"' ->
191+
"\\\""
192+
193+
'\\' ->
194+
"\\\\"
195+
196+
_ ->
197+
String.fromChar c
198+
)
199+
|> String.concat
205200

206201

207202

0 commit comments

Comments
 (0)