[PATCH] D112646: [clang-tidy] Add `readability-container-contains` check
Adrian Vogelsgesang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 27 11:49:36 PDT 2021
avogelsgesang created this revision.
Herald added subscribers: carlosgalvezp, xazax.hun, mgorny.
avogelsgesang requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.
This commit introduces a new check `readability-container-contains`
which finds usages of `container.count()` which should be replaced
by a call to 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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D112646
Files:
clang-tools-extra/clang-tidy/readability/CMakeLists.txt
clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.h
clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst
clang-tools-extra/docs/clang-tidy/checks/readability-container-contains.rst
clang-tools-extra/test/clang-tidy/checkers/readability-container-contains.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112646.382739.patch
Type: text/x-patch
Size: 19925 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211027/df5f6bbf/attachment-0001.bin>
More information about the cfe-commits
mailing list