Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve printing of several arguments #55754

Merged
merged 5 commits into from
Sep 20, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions base/strings/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ end
function print(io::IO, xs...)
lock(io)
try
for x in xs
print(io, x)
end
foreach(Fix1(print, io), xs)
finally
unlock(io)
end
Expand Down Expand Up @@ -138,32 +136,22 @@ function print_to_string(xs...)
if isempty(xs)
return ""
end
siz::Int = 0
for x in xs
siz += _str_sizehint(x)
end
siz = sum(_str_sizehint, xs; init = 0)
# specialized for performance reasons
gdalle marked this conversation as resolved.
Show resolved Hide resolved
s = IOBuffer(sizehint=siz)
for x in xs
print(s, x)
end
print(s, xs...)
String(_unsafe_take!(s))
end

function string_with_env(env, xs...)
if isempty(xs)
return ""
end
siz::Int = 0
for x in xs
siz += _str_sizehint(x)
end
siz = sum(_str_sizehint, xs; init = 0)
# specialized for performance reasons
gdalle marked this conversation as resolved.
Show resolved Hide resolved
s = IOBuffer(sizehint=siz)
env_io = IOContext(s, env)
for x in xs
print(env_io, x)
end
print(env_io, xs...)
String(_unsafe_take!(s))
end

Expand Down