Skip to content

Commit 94e3e09

Browse files
base: use eachsplit where possible
1 parent 4d1e0b2 commit 94e3e09

9 files changed

+17
-16
lines changed

base/binaryplatforms.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ function Base.parse(::Type{Platform}, triplet::AbstractString; validate_strict::
706706
libstdcxx_version = get_field(m, libstdcxx_version_mapping)
707707
cxxstring_abi = get_field(m, cxxstring_abi_mapping)
708708
function split_tags(tagstr)
709-
tag_fields = filter(!isempty, split(tagstr, "-"))
709+
tag_fields = split(tagstr, "-"; keepempty=false)
710710
if isempty(tag_fields)
711711
return Pair{String,String}[]
712712
end

base/cmd.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ function addenv(cmd::Cmd, env::Dict; inherit::Bool = true)
262262
merge!(new_env, ENV)
263263
end
264264
else
265-
for (k, v) in split.(cmd.env, "=")
265+
for (k, v) in eachsplit.(cmd.env, "=")
266266
new_env[string(k)::String] = string(v)::String
267267
end
268268
end
@@ -277,7 +277,7 @@ function addenv(cmd::Cmd, pairs::Pair{<:AbstractString}...; inherit::Bool = true
277277
end
278278

279279
function addenv(cmd::Cmd, env::Vector{<:AbstractString}; inherit::Bool = true)
280-
return addenv(cmd, Dict(k => v for (k, v) in split.(env, "=")); inherit)
280+
return addenv(cmd, Dict(k => v for (k, v) in eachsplit.(env, "=")); inherit)
281281
end
282282

283283
(&)(left::AbstractCmd, right::AbstractCmd) = AndCmds(left, right)

base/initdefs.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function init_depot_path()
101101
if haskey(ENV, "JULIA_DEPOT_PATH")
102102
str = ENV["JULIA_DEPOT_PATH"]
103103
isempty(str) && return
104-
for path in split(str, Sys.iswindows() ? ';' : ':')
104+
for path in eachsplit(str, Sys.iswindows() ? ';' : ':')
105105
if isempty(path)
106106
append_default_depot_path!(DEPOT_PATH)
107107
else
@@ -199,7 +199,7 @@ end
199199
function parse_load_path(str::String)
200200
envs = String[]
201201
isempty(str) && return envs
202-
for env in split(str, Sys.iswindows() ? ';' : ':')
202+
for env in eachsplit(str, Sys.iswindows() ? ';' : ':')
203203
if isempty(env)
204204
for env′ in DEFAULT_LOAD_PATH
205205
env′ in envs || push!(envs, env′)

base/logging.jl

+5-4
Original file line numberDiff line numberDiff line change
@@ -646,10 +646,11 @@ function handle_message(logger::SimpleLogger, level::LogLevel, message, _module,
646646
buf = IOBuffer()
647647
iob = IOContext(buf, logger.stream)
648648
levelstr = level == Warn ? "Warning" : string(level)
649-
msglines = split(chomp(string(message)::String), '\n')
650-
println(iob, "", levelstr, ": ", msglines[1])
651-
for i in 2:length(msglines)
652-
println(iob, "", msglines[i])
649+
msglines = eachsplit(chomp(string(message)::String), '\n')
650+
msg1, rest = Iterators.peel(msglines)
651+
println(iob, "", levelstr, ": ", msg1)
652+
for msg in rest
653+
println(iob, "", msg)
653654
end
654655
for (key, val) in kwargs
655656
key === :maxlog && continue

base/mpfr.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ function string_mpfr(x::BigFloat, fmt::String)
962962
end
963963

964964
function _prettify_bigfloat(s::String)::String
965-
mantissa, exponent = split(s, 'e')
965+
mantissa, exponent = eachsplit(s, 'e')
966966
if !occursin('.', mantissa)
967967
mantissa = string(mantissa, '.')
968968
end
@@ -973,7 +973,7 @@ function _prettify_bigfloat(s::String)::String
973973
expo = parse(Int, exponent)
974974
if -5 < expo < 6
975975
expo == 0 && return mantissa
976-
int, frac = split(mantissa, '.')
976+
int, frac = eachsplit(mantissa, '.')
977977
if expo > 0
978978
expo < length(frac) ?
979979
string(int, frac[1:expo], '.', frac[expo+1:end]) :

base/path.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@ function normpath(path::String)
346346
isabs = isabspath(path)
347347
isdir = isdirpath(path)
348348
drive, path = splitdrive(path)
349-
parts = split(path, path_separator_re)
350-
filter!(x->!isempty(x) && x!=".", parts)
349+
parts = split(path, path_separator_re; keepempty=false)
350+
filter!(!=("."), parts)
351351
while true
352352
clean = true
353353
for j = 1:length(parts)-1

base/sysinfo.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ function which(program_name::String)
499499
# If we have been given just a program name (not a relative or absolute
500500
# path) then we should search `PATH` for it here:
501501
pathsep = iswindows() ? ';' : ':'
502-
path_dirs = abspath.(split(get(ENV, "PATH", ""), pathsep))
502+
path_dirs = map(abspath, eachsplit(get(ENV, "PATH", ""), pathsep))
503503

504504
# On windows we always check the current directory as well
505505
if iswindows()

base/util.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function with_output_color(@nospecialize(f::Function), color::Union{Int, Symbol}
9797
(bold ? disable_text_style[:bold] : "") *
9898
get(disable_text_style, color, text_colors[:default])
9999
first = true
100-
for line in split(str, '\n')
100+
for line in eachsplit(str, '\n')
101101
first || print(buf, '\n')
102102
first = false
103103
isempty(line) && continue

base/version.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const VERSION_REGEX = r"^
100100
$"ix
101101

102102
function split_idents(s::AbstractString)
103-
idents = split(s, '.')
103+
idents = eachsplit(s, '.')
104104
pidents = Union{UInt64,String}[occursin(r"^\d+$", ident) ? parse(UInt64, ident) : String(ident) for ident in idents]
105105
return tuple(pidents...)::VerTuple
106106
end

0 commit comments

Comments
 (0)