Skip to content

Commit

Permalink
Speedup OpamTreeCommand.run
Browse files Browse the repository at this point in the history
Co-authored-by: R. Boujbel <[email protected]>
  • Loading branch information
kit-ty-kate and rjbou committed Aug 15, 2023
1 parent 65b1b53 commit 8b604aa
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/client/opamTreeCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -429,14 +429,16 @@ let raw_state tog st install =
simulate_new_state tog st universe install names

let run st tog ?no_constraint ?(no_switch=false) mode filter atoms =
let open OpamPackage.Set.Op in
let select, missing =
List.fold_left (fun (select, missing) atom ->
if OpamPackage.Set.disjoint
(OpamSwitchState.packages_of_atoms st [atom])
st.installed
then (select, atom :: missing)
else (fst atom :: select, missing)
) ([], []) atoms
let installed =
OpamPackage.Set.filter (OpamFormula.check atom) st.installed
in
if OpamPackage.Set.is_empty installed then
(select, atom :: missing)
else (installed ++ select, missing))
(OpamPackage.Set.empty, []) atoms
in
let st, universe =
let universe = get_universe tog st in
Expand All @@ -455,15 +457,19 @@ let run st tog ?no_constraint ?(no_switch=false) mode filter atoms =
(match missing with | [_] -> "" | _ -> "s")
(OpamStd.Format.pretty_list
(List.map (fun (name, _) -> OpamPackage.Name.to_string name) missing));
if select = [] && atoms <> [] then
if OpamPackage.Set.is_empty select && atoms <> [] then
OpamConsole.error_and_exit `Not_found "No package to display"
else
st, universe
in
if OpamPackage.Set.is_empty st.installed then
OpamConsole.error_and_exit `Not_found "No package is installed"
else
let forest = build st universe tog mode filter (select @ List.map fst missing) in
let simulated = OpamFormula.packages_of_atoms st.installed missing in
let forest =
build st universe tog mode filter
(OpamPackage.Name.Set.to_list (OpamPackage.names_of_packages (select ++ simulated)))
in
print ?no_constraint forest;
if OpamClientConfig.(!r.json_out) <> None then
(if not no_switch then
Expand Down

0 comments on commit 8b604aa

Please sign in to comment.