Preanal: reduce garbage

Summary:
- do not `List.rev` for `List.last`
- `List.rev_filter_map` rather than `filter |> map |> rev`

Reviewed By: da319

Differential Revision: D8185619

fbshipit-source-id: aeb41a4
master
Mehdi Bouaziz 7 years ago committed by Facebook Github Bot
parent a4098f2499
commit eaf4490670

@ -111,7 +111,7 @@ module Node = struct
(** Get the source location of the last instruction in the node *) (** Get the source location of the last instruction in the node *)
let get_last_loc n = let get_last_loc n =
match List.rev (get_instrs n) with instr :: _ -> Sil.instr_get_loc instr | [] -> n.loc n |> get_instrs |> List.last |> Option.value_map ~f:Sil.instr_get_loc ~default:n.loc
let pp_id f id = F.pp_print_int f id let pp_id f id = F.pp_print_int f id

@ -74,7 +74,7 @@ module NullifyTransferFunctions = struct
let last_instr_in_node node = let last_instr_in_node node =
let get_last_instr () = let get_last_instr () =
let instrs = CFG.instrs node in let instrs = CFG.instrs node in
match List.rev instrs with instr :: _ -> instr | [] -> Sil.skip_instr List.last instrs |> Option.value ~default:Sil.skip_instr
in in
if phys_equal node !cache_node then !cache_instr if phys_equal node !cache_node then !cache_instr
else else
@ -135,9 +135,10 @@ let add_nullify_instrs pdesc tenv liveness_inv_map =
let node_add_nullify_instructions node pvars = let node_add_nullify_instructions node pvars =
let loc = Procdesc.Node.get_last_loc node in let loc = Procdesc.Node.get_last_loc node in
let nullify_instrs = let nullify_instrs =
List.filter ~f:is_local pvars |> List.map ~f:(fun pvar -> Sil.Nullify (pvar, loc)) List.rev_filter_map pvars ~f:(fun pvar ->
if is_local pvar then Some (Sil.Nullify (pvar, loc)) else None )
in in
if nullify_instrs <> [] then Procdesc.Node.append_instrs node (List.rev nullify_instrs) if nullify_instrs <> [] then Procdesc.Node.append_instrs node nullify_instrs
in in
let node_add_removetmps_instructions node ids = let node_add_removetmps_instructions node ids =
if ids <> [] then if ids <> [] then

Loading…
Cancel
Save