Skip to content

Commit 2d86bf5

Browse files
authored
⚡️ Tail-call optimize function captures
1 parent 23a5899 commit 2d86bf5

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/glam/doc.gleam

+16-12
Original file line numberDiff line numberDiff line change
@@ -594,28 +594,32 @@ fn do_to_string(
594594
|> do_to_string(max_width, indent, rest)
595595
}
596596

597-
ForceBreak(doc) ->
598-
[#(indent, ForceBroken, doc), ..rest]
599-
|> do_to_string(acc, max_width, current_width, _)
597+
ForceBreak(doc) -> {
598+
let docs = [#(indent, ForceBroken, doc), ..rest]
599+
do_to_string(acc, max_width, current_width, docs)
600+
}
600601

601-
Concat(docs) ->
602-
list.map(docs, fn(doc) { #(indent, mode, doc) })
603-
|> list.append(rest)
604-
|> do_to_string(acc, max_width, current_width, _)
602+
Concat(docs) -> {
603+
let docs =
604+
list.map(docs, fn(doc) { #(indent, mode, doc) })
605+
|> list.append(rest)
606+
do_to_string(acc, max_width, current_width, docs)
607+
}
605608

606609
Group(doc) -> {
607610
let fits = fits([#(indent, Unbroken, doc)], max_width, current_width)
608611
let new_mode = case fits {
609612
True -> Unbroken
610613
False -> Broken
611614
}
612-
[#(indent, new_mode, doc), ..rest]
613-
|> do_to_string(acc, max_width, current_width, _)
615+
let docs = [#(indent, new_mode, doc), ..rest]
616+
do_to_string(acc, max_width, current_width, docs)
614617
}
615618

616-
Nest(doc, i) ->
617-
[#(indent + i, mode, doc), ..rest]
618-
|> do_to_string(acc, max_width, current_width, _)
619+
Nest(doc, i) -> {
620+
let docs = [#(indent + i, mode, doc), ..rest]
621+
do_to_string(acc, max_width, current_width, docs)
622+
}
619623

620624
Text(text: text, length: length) ->
621625
do_to_string(acc <> text, max_width, current_width + length, rest)

0 commit comments

Comments
 (0)