diff options
author | Adrian Vogelsgesang <avogelsgesang@tableau.com> | 2021-10-27 11:49:00 -0700 |
---|---|---|
committer | Whisperity <whisperity@gmail.com> | 2022-01-24 12:57:18 +0100 |
commit | 3696c70e67d9b9e54307ef25077bae7a6f76636e (patch) | |
tree | 7b51f2e955146c810f5af846d8170998167f6862 /clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp | |
parent | 3e50593b18840ab4508a25d0f761afb65535a38d (diff) | |
download | llvm-3696c70e67d9b9e54307ef25077bae7a6f76636e.zip llvm-3696c70e67d9b9e54307ef25077bae7a6f76636e.tar.gz llvm-3696c70e67d9b9e54307ef25077bae7a6f76636e.tar.bz2 |
[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
Diffstat (limited to 'clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp')
-rw-r--r-- | clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp index b0493d4..6bbef6b 100644 --- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp @@ -12,6 +12,7 @@ #include "AvoidConstParamsInDecls.h" #include "BracesAroundStatementsCheck.h" #include "ConstReturnTypeCheck.h" +#include "ContainerContainsCheck.h" #include "ContainerDataPointerCheck.h" #include "ContainerSizeEmptyCheck.h" #include "ConvertMemberFunctionsToStatic.h" @@ -64,6 +65,8 @@ public: "readability-braces-around-statements"); CheckFactories.registerCheck<ConstReturnTypeCheck>( "readability-const-return-type"); + CheckFactories.registerCheck<ContainerContainsCheck>( + "readability-container-contains"); CheckFactories.registerCheck<ContainerDataPointerCheck>( "readability-container-data-pointer"); CheckFactories.registerCheck<ContainerSizeEmptyCheck>( |