Skip to content

Commit 0b4dd1e

Browse files
committed
Add contains() to custom containers and use where possible. NFC
This matches the C++20 API that we cannot quite use yet. At least not until #8218 lands.
1 parent 74e21a6 commit 0b4dd1e

5 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/passes/DeadArgumentElimination2.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,7 @@ void DAE2::collectStats() {
14961496
if (auto* loc = std::get_if<FuncParamLoc>(&node)) {
14971497
auto [funcIndex, paramIndex] = *loc;
14981498
for (auto loc : parent.funcInfos[funcIndex].callerParams[paramIndex]) {
1499-
if (optimizedNodes.count(loc)) {
1499+
if (optimizedNodes.contains(loc)) {
15001500
push(loc);
15011501
}
15021502
}
@@ -1505,7 +1505,7 @@ void DAE2::collectStats() {
15051505
if (auto it = parent.typeTreeInfos.find(funcType);
15061506
it != parent.typeTreeInfos.end()) {
15071507
for (auto loc : it->second.callerParams[paramIndex]) {
1508-
if (optimizedNodes.count(loc)) {
1508+
if (optimizedNodes.contains(loc)) {
15091509
push(loc);
15101510
}
15111511
}

src/passes/TypeMerging.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ bool TypeMerging::merge(MergeKind kind) {
396396
super &&
397397
std::any_of(chain.begin(), chain.end(), [&](HeapType t) -> bool {
398398
auto super = t.getDeclaredSuperType();
399-
return super && exactCastTypes.count(*super);
399+
return super && exactCastTypes.contains(*super);
400400
});
401401
if (!super || !shapeEq(type, *super) || superHasExactCast) {
402402
// Create a new partition for this type and bail.

src/support/insert_ordered.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ template<typename T> struct InsertOrderedSet {
7474
}
7575

7676
size_t count(const T& val) const { return Map.count(val); }
77+
bool contains(const T& val) const { return Map.find(val) != Map.end(); }
7778

7879
InsertOrderedSet() = default;
7980
InsertOrderedSet(const InsertOrderedSet& other) { *this = other; }
@@ -160,6 +161,7 @@ template<typename Key, typename T> struct InsertOrderedMap {
160161
size_t size() const { return Map.size(); }
161162
bool empty() const { return Map.empty(); }
162163
size_t count(const Key& k) const { return Map.count(k); }
164+
bool contains(const Key& k) const { return Map.find(k) != Map.end(); }
163165

164166
InsertOrderedMap() = default;
165167
InsertOrderedMap(const InsertOrderedMap& other) {

src/support/small_set.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,19 @@ class SmallSetBase {
185185
}
186186
}
187187

188-
size_t count(const T& x) const {
188+
size_t count(const T& x) const { return contains(x) ? 1 : 0; }
189+
190+
bool contains(const T& x) const {
189191
if (usingFixed()) {
190192
// Do a linear search.
191193
for (size_t i = 0; i < fixed.used; i++) {
192194
if (fixed.storage[i] == x) {
193-
return 1;
195+
return true;
194196
}
195197
}
196-
return 0;
198+
return false;
197199
} else {
198-
return flexible.count(x);
200+
return flexible.find(x) != flexible.end();
199201
}
200202
}
201203

src/wasm/parsing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ struct DuplicateNameScanner
115115
// TODO: This could be done in a single insert operation that checks
116116
// whether we actually inserted, if we improved
117117
// SmallSetBase::insert to return a value like std::set does.
118-
if (seen.count(name)) {
118+
if (seen.contains(name)) {
119119
// A name has been defined more than once; we'll need to fix that.
120120
ok = false;
121121
} else {

0 commit comments

Comments
 (0)