[minor] Use List.is_empty instead of List.length equal to 0

Reviewed By: mbouaziz, jvillard

Differential Revision: D7909827

fbshipit-source-id: 4ea8b90
master
Daiva Naudziuniene 7 years ago committed by Facebook Github Bot
parent 5e6c859922
commit 28b696881c

@ -14,7 +14,7 @@ open! IStd
module F = Format module F = Format
let list_to_string list = let list_to_string list =
if Int.equal (List.length list) 0 then "( sub )" if List.is_empty list then "( sub )"
else "- {" ^ String.concat ~sep:", " (List.map ~f:Typ.Name.name list) ^ "}" else "- {" ^ String.concat ~sep:", " (List.map ~f:Typ.Name.name list) ^ "}"

@ -1103,7 +1103,7 @@ let pp_cfgnodelabel pdesc fmt (n: Procdesc.Node.t) =
let byvals = attributes.ProcAttributes.by_vals in let byvals = attributes.ProcAttributes.by_vals in
Format.fprintf fmt "Start %s\\nFormals: %a\\nLocals: %a" pname_string (pp_etlist byvals) Format.fprintf fmt "Start %s\\nFormals: %a\\nLocals: %a" pname_string (pp_etlist byvals)
(Procdesc.get_formals pdesc) pp_local_list (Procdesc.get_locals pdesc) ; (Procdesc.get_formals pdesc) pp_local_list (Procdesc.get_locals pdesc) ;
if List.length (Procdesc.get_captured pdesc) <> 0 then if not (List.is_empty (Procdesc.get_captured pdesc)) then
Format.fprintf fmt "\\nCaptured: %a" pp_var_list (Procdesc.get_captured pdesc) ; Format.fprintf fmt "\\nCaptured: %a" pp_var_list (Procdesc.get_captured pdesc) ;
let method_annotation = attributes.ProcAttributes.method_annotation in let method_annotation = attributes.ProcAttributes.method_annotation in
if not (Annot.Method.is_empty method_annotation) then if not (Annot.Method.is_empty method_annotation) then

@ -1390,7 +1390,7 @@ let exe_call_postprocess tenv ret_id trace_call callee_pname callee_attrs loc re
let should_add_ret_attr _ = let should_add_ret_attr _ =
let is_likely_getter = function let is_likely_getter = function
| Typ.Procname.Java pn_java -> | Typ.Procname.Java pn_java ->
Int.equal (List.length (Typ.Procname.Java.get_parameters pn_java)) 0 List.is_empty (Typ.Procname.Java.get_parameters pn_java)
| _ -> | _ ->
false false
in in

@ -223,7 +223,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
let rhs_base, al = AccessExpression.to_access_path rhs_access_expr in let rhs_base, al = AccessExpression.to_access_path rhs_access_expr in
let uninit_vars' = D.remove lhs_ap astate.uninit_vars in let uninit_vars' = D.remove lhs_ap astate.uninit_vars in
let uninit_vars = let uninit_vars =
if Int.equal (List.length apl) 0 then if List.is_empty apl then
(* if we assign to the root of a struct then we need to remove all the fields *) (* if we assign to the root of a struct then we need to remove all the fields *)
remove_all_fields tenv (lhs_var, lhs_typ) uninit_vars' remove_all_fields tenv (lhs_var, lhs_typ) uninit_vars'
else uninit_vars' else uninit_vars'

@ -552,7 +552,7 @@ let get_objc_property_accessor tenv ms =
(** Creates a procedure description. *) (** Creates a procedure description. *)
let create_local_procdesc ?(set_objc_accessor_attr= false) trans_unit_ctx cfg tenv ms fbody let create_local_procdesc ?(set_objc_accessor_attr= false) trans_unit_ctx cfg tenv ms fbody
captured = captured =
let defined = not (Int.equal (List.length fbody) 0) in let defined = not (List.is_empty fbody) in
let proc_name = ms.CMethodSignature.name in let proc_name = ms.CMethodSignature.name in
let pname = Typ.Procname.to_string proc_name in let pname = Typ.Procname.to_string proc_name in
let attributes = sil_func_attributes_of_attributes ms.CMethodSignature.attributes in let attributes = sil_func_attributes_of_attributes ms.CMethodSignature.attributes in

@ -2152,7 +2152,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
| None -> | None ->
create_var_exp_tmp_var trans_state expr_info "SIL_init_list__" create_var_exp_tmp_var trans_state expr_info "SIL_init_list__"
in in
if Int.equal (List.length stmts) 0 then if List.is_empty stmts then
(* perform zero initialization of a primitive type, record types will have (* perform zero initialization of a primitive type, record types will have
ImplicitValueInitExpr nodes *) ImplicitValueInitExpr nodes *)
let exps = let exps =

@ -77,7 +77,7 @@ let get_exit_location source_file bytecode =
let retrieve_fieldname fieldname = let retrieve_fieldname fieldname =
try try
let subs = Str.split (Str.regexp (Str.quote ".")) (Typ.Fieldname.to_string fieldname) in let subs = Str.split (Str.regexp (Str.quote ".")) (Typ.Fieldname.to_string fieldname) in
if Int.equal (List.length subs) 0 then assert false else List.last_exn subs List.last_exn subs
with _ -> assert false with _ -> assert false

Loading…
Cancel
Save