Skip to content

Commit 9aaff41

Browse files
authored
Clang-Tidy: readability-container-contains (AMReX-Codes#5366)
1 parent 18c3d0c commit 9aaff41

13 files changed

Lines changed: 26 additions & 29 deletions

.clang-tidy

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ Checks: >
5353
readability-*,
5454
-readability-avoid-nested-conditional-operator,
5555
-readability-avoid-unconditional-preprocessor-if,
56-
-readability-container-contains,
5756
-readability-else-after-return,
5857
-readability-function-cognitive-complexity,
5958
-readability-function-size,
@@ -85,4 +84,3 @@ HeaderFileExtensions: ['', "H", 'h', 'hh', 'hpp', 'hxx']
8584
# -modernize-use-ranges
8685
# -modernize-use-integer-sign-comparison
8786
# -modernize-use-starts-ends-with
88-
# -readability-container-contains

Src/Base/AMReX_CArena.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ CArena::alloc_protected (std::size_t nbytes)
121121
else
122122
{
123123
BL_ASSERT((*free_it).size() >= nbytes);
124-
BL_ASSERT(m_busylist.find(*free_it) == m_busylist.end());
124+
BL_ASSERT(!m_busylist.contains(*free_it));
125125

126126
vp = (*free_it).block();
127127

@@ -174,7 +174,7 @@ CArena::alloc_in_place (void* pt, std::size_t szmin, std::size_t szmax)
174174
amrex::Abort("CArena::alloc_in_place: unknown pointer");
175175
return std::make_pair(nullptr,0);
176176
}
177-
AMREX_ASSERT(m_freelist.find(*busy_it) == m_freelist.end());
177+
AMREX_ASSERT(!m_freelist.contains(*busy_it));
178178

179179
if (busy_it->size() >= szmax) {
180180
return std::make_pair(pt, busy_it->size());
@@ -248,7 +248,7 @@ CArena::shrink_in_place (void* pt, std::size_t new_size)
248248
amrex::Abort("CArena::shrink_in_place: unknown pointer");
249249
return nullptr;
250250
}
251-
AMREX_ASSERT(m_freelist.find(*busy_it) == m_freelist.end());
251+
AMREX_ASSERT(!m_freelist.contains(*busy_it));
252252

253253
auto const old_size = busy_it->size();
254254

@@ -312,7 +312,7 @@ CArena::free (void* vp)
312312
amrex::Abort("CArena::free: unknown pointer");
313313
return;
314314
}
315-
BL_ASSERT(m_freelist.find(*busy_it) == m_freelist.end());
315+
BL_ASSERT(!m_freelist.contains(*busy_it));
316316

317317
m_actually_used -= busy_it->size();
318318

Src/Base/AMReX_FACopyDescriptor.H

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ FabArrayCopyDescriptor<FAB>::CollectData ()
475475

476476
Total_Rcvs_Size += Cnt;
477477

478-
if (Rcvs.count(Who) > 0)
478+
if (Rcvs.contains(Who))
479479
{
480480
Rcvs[Who] += 1;
481481
}
@@ -484,7 +484,7 @@ FabArrayCopyDescriptor<FAB>::CollectData ()
484484
Rcvs[Who] = 1;
485485
}
486486

487-
if (Npts.count(Who) > 0)
487+
if (Npts.contains(Who))
488488
{
489489
Npts[Who] += Cnt;
490490
}
@@ -493,7 +493,7 @@ FabArrayCopyDescriptor<FAB>::CollectData ()
493493
Npts[Who] = Cnt;
494494
}
495495
}
496-
BL_ASSERT(Rcvs.count(MyProc) == 0);
496+
BL_ASSERT(!Rcvs.contains(MyProc));
497497

498498
BL_ASSERT((Total_Rcvs_Size*sizeof(value_type))
499499
< static_cast<std::size_t>(std::numeric_limits<int>::max()));

Src/Base/AMReX_ForkJoin.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class ForkJoin
106106
// TODO: may want to de-register MFs if they change across invocations
107107

108108
MultiFab &get_mf (const std::string &name, int idx = 0) {
109-
AMREX_ASSERT_WITH_MESSAGE(data.count(name) > 0 && idx < data[name].size(), "get_mf(): name or index not found");
109+
AMREX_ASSERT_WITH_MESSAGE(data.contains(name) && idx < data[name].size(), "get_mf(): name or index not found");
110110
AMREX_ASSERT(task_me >= 0 && task_me < data[name][idx].forked.size());
111111
return data[name][idx].forked[task_me];
112112
}

Src/Base/AMReX_ForkJoin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ ForkJoin::reg_mf (MultiFab &mf, const std::string &name, int idx,
140140
void
141141
ForkJoin::modify_ngrow (const std::string &name, int idx, IntVect ngrow)
142142
{
143-
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(data.count(name) > 0 && data[name].size() > idx,
143+
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(data.contains(name) && data[name].size() > idx,
144144
"(name, index) pair doesn't exist");
145145
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(!flag_invoked,
146146
"Can only specify grow cells before first forkjoin() invocation");
@@ -154,7 +154,7 @@ ForkJoin::modify_ngrow (const std::string &name, int idx, IntVect ngrow)
154154
void
155155
ForkJoin::modify_split (const std::string &name, int idx, Vector<ComponentSet> comp_split)
156156
{
157-
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(data.count(name) > 0 && data[name].size() > idx,
157+
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(data.contains(name) && data[name].size() > idx,
158158
"(name, index) pair doesn't exist");
159159
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(!flag_invoked,
160160
"Can only specify custom split before first forkjoin() invocation");

Src/Base/AMReX_Random.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ UniqueRandomSubset (Vector<int> &uSet, int setSize, int poolSize,
208208
uSet.clear();
209209
while(static_cast<int>(copySet.size()) < setSize) {
210210
int r = static_cast<int>(Random_int(poolSize));
211-
if(copySet.find(r) == copySet.end()) {
211+
if(!copySet.contains(r)) {
212212
copySet.insert(r);
213213
uSet.push_back(r);
214214
}

Src/Base/AMReX_TinyProfiler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ TinyProfiler::Finalize (bool bFlushing)
421421

422422
if (!alreadySynced) {
423423
for (auto const& s : syncedRegions) {
424-
if (lstatsmap.find(s) == lstatsmap.end()) {
424+
if (!lstatsmap.contains(s)) {
425425
lstatsmap.insert(std::make_pair(s,std::map<std::string,Stats>()));
426426
}
427427
}
@@ -529,7 +529,7 @@ TinyProfiler::PrintStats (std::map<std::string,Stats>& regstats, double dt_max,
529529

530530
if (! alreadySynced) { // add the new name
531531
for (auto const& s : syncedStrings) {
532-
if (regstats.find(s) == regstats.end()) {
532+
if (!regstats.contains(s)) {
533533
regstats.insert(std::make_pair(s, Stats()));
534534
}
535535
}
@@ -744,7 +744,7 @@ TinyProfiler::PrintMemStats (std::map<std::string, MemStat>& memstats,
744744

745745
if (! alreadySynced) { // add the new name
746746
for (auto const& s : syncedStrings) {
747-
if (memstats.find(s) == memstats.end()) {
747+
if (!memstats.contains(s)) {
748748
memstats[s]; // insert
749749
}
750750
}

Src/Base/AMReX_VisMF.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ Read (FabArray<FAB>& fa, const std::string& name)
668668
auto whichread = allreads[fi].begin();
669669
for ( ; whichread != allreads[fi].end(); ++whichread) {
670670
const int tryproc = whichread->first;
671-
if (busyprocs.find(tryproc) == busyprocs.end()) { // not busy
671+
if (!busyprocs.contains(tryproc)) { // not busy
672672
busyprocs.insert(tryproc);
673673
Vector<int> vreads;
674674
vreads.reserve(whichread->second.size());

Src/Base/AMReX_VisMF.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,7 +1752,7 @@ VisMF::Read (FabArray<FArrayBox> &mf,
17521752
readRanks.push_back(*setIter);
17531753
}
17541754

1755-
if(rfrSet.find(myProc) != rfrSet.end()) { // ---- myProc needs to read this file
1755+
if(rfrSet.contains(myProc)) { // ---- myProc needs to read this file
17561756
const std::string &fileName = rfrIter->first;
17571757
std::string fullFileName(VisMF::DirName(mf_name) + fileName);
17581758
frcIter = FileReadChains.find(fileName);
@@ -1968,7 +1968,7 @@ VisMF::Read (FabArray<FArrayBox> &mf,
19681968
whichRead != allReads[arIndex].end(); ++whichRead)
19691969
{
19701970
int tryProc(whichRead->first);
1971-
if(busyProcs.find(tryProc) == busyProcs.end()) { // tryProc not busy
1971+
if(!busyProcs.contains(tryProc)) { // tryProc not busy
19721972
busyProcs.insert(tryProc);
19731973
int nReads= static_cast<int>(whichRead->second.size());
19741974
int ir(0);

Src/Extern/SENSEI/AMReX_ParticleDataAdaptorI.H

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,22 +331,22 @@ int ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt, Allocator>::AddArra
331331
return -1;
332332
}
333333

334-
if(m_realStructs.find(arrayName) != m_realStructs.end())
334+
if(m_realStructs.contains(arrayName))
335335
{
336336
return this->AddParticlesAOSRealArray(arrayName, mesh);
337337
}
338338

339-
if(m_intStructs.find(arrayName) != m_intStructs.end())
339+
if(m_intStructs.contains(arrayName))
340340
{
341341
return this->AddParticlesAOSIntArray(arrayName, mesh);
342342
}
343343

344-
if(m_realArrays.find(arrayName) != m_realArrays.end())
344+
if(m_realArrays.contains(arrayName))
345345
{
346346
return this->AddParticlesSOARealArray(arrayName, mesh);
347347
}
348348

349-
if(m_intArrays.find(arrayName) != m_intArrays.end())
349+
if(m_intArrays.contains(arrayName))
350350
{
351351
return this->AddParticlesSOAIntArray(arrayName, mesh);
352352
}

0 commit comments

Comments
 (0)