Skip to content

Commit

Permalink
Manually split `string(a::Union{Char, String, SubString{String}, Symb…
Browse files Browse the repository at this point in the history
…ol}...)` (#43939)

* Manually split `string(a::Union{Char, String, SubString{String}, Symbol}...)`

4 is one too many for automatic Union-splitting.  Poor inference in
this method accounts for more than 1000 invalidations.
  • Loading branch information
timholy authored Jan 26, 2022
1 parent f1e7f52 commit 051ab3b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion base/strings/substring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,16 @@ end
function string(a::Union{Char, String, SubString{String}, Symbol}...)
n = 0
for v in a
# 4 types is too many for automatic Union-splitting, so we split manually
# and allow one specializable call site per concrete type
if v isa Char
n += ncodeunits(v)
else
elseif v isa String
n += sizeof(v)
elseif v isa SubString{String}
n += sizeof(v)
else
n += sizeof(v::Symbol)
end
end
out = _string_n(n)
Expand Down

0 comments on commit 051ab3b

Please sign in to comment.