ocaml.lang.performance.list.ocamllint-length-list-zero

profile photo of semgrepsemgrep
Author
4,866
Download Count*

You probably want $X = [], which is faster.

Run Locally

Run in CI

Defintion

rules:
  - id: ocamllint-length-list-zero
    pattern: List.length $X = 0
    message: You probably want $X = [], which is faster.
    languages:
      - ocaml
    severity: WARNING
    metadata:
      category: performance
      technology:
        - ocaml
      license: Commons Clause License Condition v1.0[LGPL-2.1-only]

Examples

list.ml

let test xs =
  (* ruleid:ocamllint-length-list-zero *)
  if List.length xs = 0
  then 1
  else 2

let test2 xs =
  (* ruleid:ocamllint-length-more-than-zero *)
  if List.length xs > 0
  then 1
  else 2