Skip to content

Commit

Permalink
stdlib: implement List.is_empty using pattern-matching
Browse files Browse the repository at this point in the history
As of ocaml#10681, the native compiler is able to simplify this
pattern-matching to use bitwise operations rather than an explicit
branch (as was previously the case) or an integer comparison (as is the
case for the implementation using `( = )`).
  • Loading branch information
craigfe committed Nov 6, 2021
1 parent fa70326 commit ce4bb2f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion stdlib/list.ml
Expand Up @@ -549,7 +549,9 @@ let rec compare_length_with l n =
compare_length_with l (n-1)
;;

let is_empty l = (l = [])
let is_empty = function
| [] -> true
| _ :: _ -> false

(** {1 Comparison} *)

Expand Down

0 comments on commit ce4bb2f

Please sign in to comment.