From 3f67ca3f80a1348775d6c1d1344f12a9f8cecd1f Mon Sep 17 00:00:00 2001 From: Jeremy Dubreil Date: Thu, 20 Apr 2017 16:12:29 -0700 Subject: [PATCH] [infer][java] avoid unecessary convertions from sets to lists of call sites Summary: These convertions from sets to lists were not necessary Reviewed By: sblackshear Differential Revision: D4900883 fbshipit-source-id: 670821c --- infer/src/checkers/annotationReachability.ml | 42 ++++++++++---------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/infer/src/checkers/annotationReachability.ml b/infer/src/checkers/annotationReachability.ml index ed743d755..89f18cd3b 100644 --- a/infer/src/checkers/annotationReachability.ml +++ b/infer/src/checkers/annotationReachability.ml @@ -137,17 +137,16 @@ let method_has_annot annot tenv pname = let method_overrides_annot annot tenv pname = method_overrides (method_has_annot annot) tenv pname -let lookup_annotation_calls caller_pdesc annot pname : CallSite.t list = +let lookup_annotation_calls caller_pdesc annot pname : CallSite.SetDomain.t = match Ondemand.analyze_proc_name ~propagate_exceptions:false caller_pdesc pname with | Some { Specs.payload = { Specs.calls = Some call_map; }; } -> begin try Annot.Map.find annot call_map - |> CallSite.SetDomain.elements with Not_found -> - [] + CallSite.SetDomain.empty end - | _ -> [] + | _ -> CallSite.SetDomain.empty let update_trace loc trace = if Location.equal loc Location.dummy then trace @@ -212,21 +211,21 @@ let report_call_stack summary end_of_stack lookup_next_calls report call_site ca let new_stack_str = stack_str ^ callee_pname_str ^ " -> " in let new_trace = update_trace call_loc trace |> update_trace callee_def_loc in let unseen_pnames, updated_visited = - List.fold - ~f:(fun (accu, set) call_site -> - let p = CallSite.pname call_site in - let loc = CallSite.loc call_site in - if Typ.Procname.Set.mem p set then (accu, set) - else ((p, loc) :: accu, Typ.Procname.Set.add p set)) - ~init:([], visited_pnames) - next_calls in + CallSite.SetDomain.fold + (fun call_site ((unseen, visited) as accu) -> + let p = CallSite.pname call_site in + let loc = CallSite.loc call_site in + if Typ.Procname.Set.mem p visited then accu + else ((p, loc) :: unseen, Typ.Procname.Set.add p visited)) + next_calls + ([], visited_pnames) in List.iter ~f:(loop fst_call_loc updated_visited (new_trace, new_stack_str)) unseen_pnames in - List.iter - ~f:(fun fst_call_site -> - let fst_callee_pname = CallSite.pname fst_call_site in - let fst_call_loc = CallSite.loc fst_call_site in - let start_trace = update_trace (CallSite.loc call_site) [] in - loop fst_call_loc Typ.Procname.Set.empty (start_trace, "") (fst_callee_pname, fst_call_loc)) + CallSite.SetDomain.iter + (fun fst_call_site -> + let fst_callee_pname = CallSite.pname fst_call_site in + let fst_call_loc = CallSite.loc fst_call_site in + let start_trace = update_trace (CallSite.loc call_site) [] in + loop fst_call_loc Typ.Procname.Set.empty (start_trace, "") (fst_callee_pname, fst_call_loc)) calls module TransferFunctions (CFG : ProcCfg.S) = struct @@ -352,9 +351,8 @@ module Interprocedural = struct let extract_calls_with_annot annot call_map = try Annot.Map.find annot call_map - |> CallSite.SetDomain.elements - with Not_found -> [] in - let report_src_snk_path (calls : CallSite.t list) (src_annot: Annot.t) = + with Not_found -> CallSite.SetDomain.empty in + let report_src_snk_path (calls : CallSite.SetDomain.t) (src_annot: Annot.t) = if method_overrides_annot src_annot tenv proc_name then let f_report = @@ -367,7 +365,7 @@ module Interprocedural = struct (CallSite.make proc_name loc) calls in let calls = extract_calls_with_annot snk_annot call_map in - if not (Int.equal (List.length calls) 0) + if not (CallSite.SetDomain.is_empty calls) then List.iter ~f:(report_src_snk_path calls) src_annot_list in let initial =