Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/passes/DeadArgumentElimination2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,7 @@ void DAE2::collectStats() {
if (auto* loc = std::get_if<FuncParamLoc>(&node)) {
auto [funcIndex, paramIndex] = *loc;
for (auto loc : parent.funcInfos[funcIndex].callerParams[paramIndex]) {
if (optimizedNodes.count(loc)) {
if (optimizedNodes.contains(loc)) {
push(loc);
}
}
Expand All @@ -1505,7 +1505,7 @@ void DAE2::collectStats() {
if (auto it = parent.typeTreeInfos.find(funcType);
it != parent.typeTreeInfos.end()) {
for (auto loc : it->second.callerParams[paramIndex]) {
if (optimizedNodes.count(loc)) {
if (optimizedNodes.contains(loc)) {
push(loc);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/passes/TypeMerging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ bool TypeMerging::merge(MergeKind kind) {
auto chain = type.getDescriptorChain();
bool hasCast =
std::any_of(chain.begin(), chain.end(), [&](HeapType t) -> bool {
return castTypes.count(t);
return castTypes.contains(t);
});
if (hasCast || !privateTypes.count(type)) {
ensurePartition(type);
Expand All @@ -396,7 +396,7 @@ bool TypeMerging::merge(MergeKind kind) {
super &&
std::any_of(chain.begin(), chain.end(), [&](HeapType t) -> bool {
auto super = t.getDeclaredSuperType();
return super && exactCastTypes.count(*super);
return super && exactCastTypes.contains(*super);
});
if (!super || !shapeEq(type, *super) || superHasExactCast) {
// Create a new partition for this type and bail.
Expand Down
2 changes: 2 additions & 0 deletions src/support/insert_ordered.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ template<typename T> struct InsertOrderedSet {
}

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

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

InsertOrderedMap() = default;
InsertOrderedMap(const InsertOrderedMap& other) {
Expand Down
12 changes: 6 additions & 6 deletions src/support/small_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,17 @@ class SmallSetBase {
}
}

size_t count(const T& x) const {
bool contains(const T& x) const {
if (usingFixed()) {
// Do a linear search.
for (size_t i = 0; i < fixed.used; i++) {
if (fixed.storage[i] == x) {
return 1;
return true;
}
}
return 0;
return false;
} else {
return flexible.count(x);
return flexible.find(x) != flexible.end();
}
}

Expand All @@ -222,11 +222,11 @@ class SmallSetBase {
if (usingFixed()) {
return std::all_of(fixed.storage.begin(),
fixed.storage.begin() + fixed.used,
[&other](const T& x) { return other.count(x); });
[&other](const T& x) { return other.contains(x); });
} else if (other.usingFixed()) {
return std::all_of(other.fixed.storage.begin(),
other.fixed.storage.begin() + other.fixed.used,
[this](const T& x) { return count(x); });
[this](const T& x) { return contains(x); });
} else {
return flexible == other.flexible;
}
Expand Down
2 changes: 1 addition & 1 deletion src/wasm/parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct DuplicateNameScanner
// TODO: This could be done in a single insert operation that checks
// whether we actually inserted, if we improved
// SmallSetBase::insert to return a value like std::set does.
if (seen.count(name)) {
if (seen.contains(name)) {
// A name has been defined more than once; we'll need to fix that.
ok = false;
} else {
Expand Down
26 changes: 13 additions & 13 deletions test/example/small_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ template<typename T>
void assertContents(T& t, const std::vector<int>& expectedContents) {
assert(t.size() == expectedContents.size());
for (auto item : expectedContents) {
assert(t.count(item) == 1);
assert(t.contains(item));
}
// Also test this using an iterator and a const iterator to also get
// coverage there.
Expand Down Expand Up @@ -69,29 +69,29 @@ template<typename T> void testAPI() {
assert(t.size() == 3);

// unwind by erasing (in the opposite direction from before)
assert(t.count(1) == 1);
assert(t.count(2) == 1);
assert(t.count(3) == 1);
assert(t.count(1337) == 0);
assert(t.contains(1));
assert(t.contains(2));
assert(t.contains(3));
assert(!t.contains(1337));

t.erase(1);
assert(t.count(1) == 0);
assert(!t.contains(1));

assert(t.size() == 2);

assert(t.count(2) == 1);
assert(t.contains(2));
t.erase(2);
assert(t.count(2) == 0);
assert(!t.contains(2));

assert(t.size() == 1);

assert(t.count(3) == 1);
assert(t.contains(3));
t.erase(3);

assert(t.count(1) == 0);
assert(t.count(2) == 0);
assert(t.count(3) == 0);
assert(t.count(1337) == 0);
assert(!t.contains(1));
assert(!t.contains(2));
assert(!t.contains(3));
assert(!t.contains(1337));

assert(t.size() == 0);
}
Expand Down
Loading