Skip to content

Commit f6041ce

Browse files
committed
Optimize getting last list element
See: goblint#966 (comment), goblint#966 (comment), goblint#966 (comment)
1 parent 6b1b5f8 commit f6041ce

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/cdomains/intDomain.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,9 +1252,9 @@ struct
12521252
| [], _ -> [] | _ ,[] -> xs
12531253
| _, _ ->
12541254
let min_xs = fst (List.hd xs) in
1255-
let max_xs = snd (List.hd (List.rev xs)) in
1255+
let max_xs = snd @@ BatList.last xs in
12561256
let min_ys = fst (List.hd ys) in
1257-
let max_ys = snd (List.hd (List.rev ys)) in
1257+
let max_ys = snd @@ BatList.last ys in
12581258
let min_range,max_range = range ik in
12591259
let min = if Ints_t.compare min_xs min_range == 0 then min_ys else min_xs in
12601260
let max = if Ints_t.compare max_xs max_range == 0 then max_ys else max_xs in
@@ -1282,7 +1282,9 @@ struct
12821282

12831283
let minimal = function [] -> None | (x, _)::_ -> Some x
12841284

1285-
let maximal xs = xs |> List.rev |> (function [] -> None | (_, y)::_ -> Some y)
1285+
let maximal = function
1286+
| [] -> None
1287+
| xs -> let last = BatList.last xs |> snd in Some last
12861288

12871289
let of_interval ik (x, y) = norm ik @@ Some (x, y)
12881290

0 commit comments

Comments
 (0)