Skip to content

Commit 3422861

Browse files
Replace list computation + empty check with short-circuiting alternatives
Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com>
1 parent 73ffb77 commit 3422861

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/check.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,9 +583,9 @@ and checkExp (isconst: bool) (e: exp) : typ =
583583
| AddrOfLabel (gref) -> begin
584584
(* Find a label *)
585585
let lab =
586-
match List.filter (function Label _ -> true | _ -> false)
586+
match List.find_opt (function Label _ -> true | _ -> false)
587587
!gref.labels with
588-
Label (lab, _, _) :: _ -> lab
588+
Some (Label (lab, _, _)) -> lab
589589
| _ ->
590590
ignore (warn "Address of label to block without a label");
591591
"<missing label>"
@@ -748,9 +748,9 @@ and checkStmt (s: stmt) =
748748
currentLoc := l;
749749
(* Find a label *)
750750
let lab =
751-
match List.filter (function Label _ -> true | _ -> false)
751+
match List.find_opt (function Label _ -> true | _ -> false)
752752
!gref.labels with
753-
Label (lab, _, _) :: _ -> lab
753+
Some (Label (lab, _, _)) -> lab
754754
| _ ->
755755
ignore (warn "Goto to block without a label");
756756
"<missing label>"

src/cil.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1427,7 +1427,7 @@ and filterAttributes (s: string) (al: attribute list) : attribute list =
14271427

14281428
(* sm: *)
14291429
let hasAttribute s al =
1430-
(filterAttributes s al <> [])
1430+
List.exists (fun (Attr(an, _)) -> an = s) al
14311431

14321432

14331433
type attributeClass =

src/frontc/cabs2cil.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5637,10 +5637,10 @@ and doInit
56375637
(* We have a designator *)
56385638
| _, (what, ie) :: restil when what != A.NEXT_INIT ->
56395639
let rec unrollDesignatorForNestedAnonymous (comp: compinfo) (designator: string) (whatnext: initwhat) =
5640-
let own_field = List.filter (fun fld -> fld.fname = designator) comp.cfields in
5640+
let own_field = List.find_opt (fun fld -> fld.fname = designator) comp.cfields in
56415641
match own_field with
5642-
| fld :: _ -> (true, Some(A.INFIELD_INIT (designator, whatnext)))
5643-
| [] ->
5642+
| Some _ -> (true, Some(A.INFIELD_INIT (designator, whatnext)))
5643+
| None ->
56445644
let anonymous_compounds = List.filter_map (fun f ->
56455645
(* f.ftype need not be unrolled here, inner anonymous struct cannot be typdef'ed *)
56465646
match f.ftype with

0 commit comments

Comments
 (0)