FWIW, all the ways to write “combine three binaries into one binary” produce identical assembly:
defmodule CombineBinaries do
@compile :S
def all_concat(a, b, c) do
a <> b <> c
end
def nested_binary(a, b, c) do
<< <<a::binary, b::binary>>::binary, c::binary>>
end
def nested_binary_flipped(a, b, c) do
<<a::binary, <<b::binary, c::binary>>::binary >>
end
def triple_binary(a, b, c) do
<<a::binary, b::binary, c::binary>>
end
end
All of the resulting functions look like this:
{function, all_concat, 3, 11}.
{label,10}.
{line,[{location,"foo.ex",4}]}.
{func_info,{atom,'Elixir.CombineBinaries'},{atom,all_concat},3}.
{label,11}.
{line,[{location,"foo.ex",5}]}.
{bs_create_bin,{f,0},
0,3,8,
{x,0},
{list,[{atom,append},
1,8,nil,
{x,0},
{atom,all},
{atom,binary},
2,8,nil,
{x,1},
{atom,all},
{atom,binary},
3,8,nil,
{x,2},
{atom,all}]}}.
return.
bs_create_bin was introduced in OTP25 as a new way to construct binaries from segments.