Skip to content

Commit 0b87d95

Browse files
sjkellyLilithHafnerjakobnissen
authored
Use in-place operations where appropriate (#50119)
This changes some uses of reverse/sort/filter to the in-place versions where appropriate. Should provide some minor memory savings. Co-authored-by: Lilith Orion Hafner <lilithhafner@gmail.com> Co-authored-by: Jakob Nybo Nissen <jakobnybonissen@gmail.com>
1 parent 0f26966 commit 0b87d95

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

base/binaryplatforms.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ end
186186
function Base.show(io::IO, p::Platform)
187187
str = string(platform_name(p), " ", arch(p))
188188
# Add on all the other tags not covered by os/arch:
189-
other_tags = sort(collect(filter(kv -> kv[1] ("os", "arch"), tags(p))))
189+
other_tags = sort!(filter!(kv -> kv[1] ("os", "arch"), collect(tags(p))))
190190
if !isempty(other_tags)
191191
str = string(str, " {", join([string(k, "=", v) for (k, v) in other_tags], ", "), "}")
192192
end
@@ -835,7 +835,7 @@ Inspects the current Julia process to determine the libgfortran version this Jul
835835
linked against (if any).
836836
"""
837837
function detect_libgfortran_version()
838-
libgfortran_paths = filter(x -> occursin("libgfortran", x), Libdl.dllist())
838+
libgfortran_paths = filter!(x -> occursin("libgfortran", x), Libdl.dllist())
839839
if isempty(libgfortran_paths)
840840
# One day, I hope to not be linking against libgfortran in base Julia
841841
return nothing
@@ -865,7 +865,7 @@ it is linked against (if any). `max_minor_version` is the latest version in the
865865
3.4 series of GLIBCXX where the search is performed.
866866
"""
867867
function detect_libstdcxx_version(max_minor_version::Int=30)
868-
libstdcxx_paths = filter(x -> occursin("libstdc++", x), Libdl.dllist())
868+
libstdcxx_paths = filter!(x -> occursin("libstdc++", x), Libdl.dllist())
869869
if isempty(libstdcxx_paths)
870870
# This can happen if we were built by clang, so we don't link against
871871
# libstdc++ at all.
@@ -897,7 +897,7 @@ between Julia and LLVM; they must match.
897897
"""
898898
function detect_cxxstring_abi()
899899
# First, if we're not linked against libstdc++, then early-exit because this doesn't matter.
900-
libstdcxx_paths = filter(x -> occursin("libstdc++", x), Libdl.dllist())
900+
libstdcxx_paths = filter!(x -> occursin("libstdc++", x), Libdl.dllist())
901901
if isempty(libstdcxx_paths)
902902
# We were probably built by `clang`; we don't link against `libstdc++`` at all.
903903
return nothing
@@ -1080,7 +1080,7 @@ function select_platform(download_info::Dict, platform::AbstractPlatform = HostP
10801080
# We prefer these better matches, and secondarily reverse-sort by triplet so
10811081
# as to generally choose the latest release (e.g. a `libgfortran5` tarball
10821082
# over a `libgfortran3` tarball).
1083-
ps = sort(ps, lt = (a, b) -> begin
1083+
sort!(ps, lt = (a, b) -> begin
10841084
loss_a = match_loss(a, platform)
10851085
loss_b = match_loss(b, platform)
10861086
if loss_a != loss_b

base/loading.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2718,7 +2718,7 @@ end
27182718

27192719
function get_preferences(uuid::Union{UUID,Nothing} = nothing)
27202720
merged_prefs = Dict{String,Any}()
2721-
for env in reverse(load_path())
2721+
for env in reverse!(load_path())
27222722
project_toml = env_project_file(env)
27232723
if !isa(project_toml, String)
27242724
continue

base/threadingconstructs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function threading_run(fun, static)
141141
Base._wait(tasks[i])
142142
end
143143
ccall(:jl_exit_threaded_region, Cvoid, ())
144-
failed_tasks = filter(istaskfailed, tasks)
144+
failed_tasks = filter!(istaskfailed, tasks)
145145
if !isempty(failed_tasks)
146146
throw(CompositeException(map(TaskFailedException, failed_tasks)))
147147
end

stdlib/REPL/src/docview.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ function doc_completions(name, mod::Module=Main)
743743
idxs = findall(!isnothing, ms)
744744

745745
# avoid messing up the order while inserting
746-
for i in reverse(idxs)
746+
for i in reverse!(idxs)
747747
c = only((ms[i]::AbstractMatch).captures)
748748
insert!(res, i, "$(c)\"\"")
749749
end

0 commit comments

Comments
 (0)