From c16a5238ee03ff7f88d3340f8ee04b17eed061d5 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Fri, 13 Oct 2023 10:15:20 -0400 Subject: [PATCH] Switch datastructure Vector -> Set for algorithmic complexity (#3652) In the same project as #3651, this code was also having trouble because of the rapidly growing alldeps, which would end up with many repeated entries. Switch the data structure to fix the algorithmic complexity here also. (cherry picked from commit 0e0cf4514f8ee32d8d53c60aa7c1d9276bfa1bde) --- src/API.jl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/API.jl b/src/API.jl index ff92efaa34..e1b8a2bc5d 100644 --- a/src/API.jl +++ b/src/API.jl @@ -1248,19 +1248,21 @@ function precompile(ctx::Context, pkgs::Vector{PackageSpec}; internal_call::Bool # if a list of packages is given, restrict to dependencies of given packages if !isempty(pkgs) pkgs_names = [p.name for p in pkgs] - function collect_all_deps(depsmap, dep, alldeps=Base.PkgId[]) - append!(alldeps, depsmap[dep]) + function collect_all_deps(depsmap, dep, alldeps=Set{Base.PkgId}()) for _dep in depsmap[dep] - collect_all_deps(depsmap, _dep, alldeps) + if !(_dep in alldeps) + push!(alldeps, _dep) + collect_all_deps(depsmap, _dep, alldeps) + end end return alldeps end - keep = Base.PkgId[] + keep = Set{Base.PkgId}() for dep in depsmap dep_pkgid = first(dep) if dep_pkgid.name in pkgs_names push!(keep, dep_pkgid) - append!(keep, collect_all_deps(depsmap, dep_pkgid)) + collect_all_deps(depsmap, dep_pkgid, keep) end end for ext in keys(exts)