[all-commits] [llvm/llvm-project] 3696c7: [clang-tidy] Add `readability-container-contains` ...

Adrian Vogelsgesang via All-commits all-commits at lists.llvm.org
Mon Jan 24 03:57:44 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 3696c70e67d9b9e54307ef25077bae7a6f76636e
      https://github.com/llvm/llvm-project/commit/3696c70e67d9b9e54307ef25077bae7a6f76636e
  Author: Adrian Vogelsgesang <avogelsgesang at tableau.com>
  Date:   2022-01-24 (Mon, 24 Jan 2022)

  Changed paths:
    M clang-tools-extra/clang-tidy/readability/CMakeLists.txt
    A clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
    A clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.h
    M clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
    M clang-tools-extra/docs/ReleaseNotes.rst
    M clang-tools-extra/docs/clang-tidy/checks/list.rst
    A clang-tools-extra/docs/clang-tidy/checks/readability-container-contains.rst
    A clang-tools-extra/test/clang-tidy/checkers/readability-container-contains.cpp

  Log Message:
  -----------
  [clang-tidy] Add `readability-container-contains` check

This commit introduces a new check `readability-container-contains` which finds
usages of `container.count()` and `container.find() != container.end()` and
instead recommends the `container.contains()` method introduced in C++20.

For containers which permit multiple entries per key (`multimap`, `multiset`,
...), `contains` is more efficient than `count` because `count` has to do
unnecessary additional work.

While this this performance difference does not exist for containers with only
a single entry per key (`map`, `unordered_map`, ...), `contains` still conveys
the intent better.

Reviewed By: xazax.hun, whisperity

Differential Revision: http://reviews.llvm.org/D112646




More information about the All-commits mailing list