Skip to content

Commit

Permalink
[litho] small code improvement
Browse files Browse the repository at this point in the history
Summary: Replaced unnecessary use of a set with a list.

Reviewed By: davidpichardie

Differential Revision: D66352846

fbshipit-source-id: ed9ec0212e510e51a234d1c97ca95d554be1ba13
  • Loading branch information
ngorogiannis authored and facebook-github-bot committed Nov 25, 2024
1 parent cad7374 commit b7b79b5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
16 changes: 2 additions & 14 deletions infer/src/checkers/LithoDomain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,17 @@ end

module LocalAccessPathSet = PrettyPrintable.MakePPSet (LocalAccessPath)

let suffixes = IString.Set.of_list ["Attr"; "Dip"; "Px"; "Res"; "Sp"]
let suffixes = ["Attr"; "Dip"; "Px"; "Res"; "Sp"]

module MethodCallPrefix = struct
type t =
{prefix: string; procname: Procname.t [@compare.ignore]; location: Location.t [@compare.ignore]}
[@@deriving compare]

exception Found of string

let make_with_prefixes procname location =
let method_name = Procname.get_method procname in
let prefix_opt =
try
IString.Set.iter
(fun suffix ->
match String.chop_suffix method_name ~suffix with
| Some res ->
raise (Found res)
| None ->
() )
suffixes ;
None
with Found res -> Some res
List.find_map suffixes ~f:(fun suffix -> String.chop_suffix method_name ~suffix)
in
let default = [{prefix= method_name; procname; location}] in
Option.value_map prefix_opt ~default ~f:(fun prefix ->
Expand Down
2 changes: 1 addition & 1 deletion infer/src/checkers/LithoDomain.mli
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module LocalAccessPath : sig
val make_from_access_expression : HilExp.AccessExpression.t -> Procname.t -> t
end

val suffixes : IString.Set.t
val suffixes : string list

(** Called procedure & location *)
module MethodCallPrefix : sig
Expand Down
3 changes: 2 additions & 1 deletion infer/src/checkers/RequiredProps.ml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ let has_prop prop_set prop =
IString.Set.exists
(fun el ->
String.chop_prefix el ~prefix:prop
|> Option.exists ~f:(fun suffix -> IString.Set.mem suffix LithoDomain.suffixes) )
|> Option.exists ~f:(fun suffix -> List.mem LithoDomain.suffixes suffix ~equal:String.equal)
)
prop_set
in
match prop with
Expand Down

0 comments on commit b7b79b5

Please sign in to comment.