Skip to content

Commit

Permalink
perf: slightly faster contains()
Browse files Browse the repository at this point in the history
  • Loading branch information
tearfur committed Feb 21, 2024
1 parent dd03342 commit 10086fc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/small/detail/container/associative_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ namespace small::detail {
std::enable_if_t<is_comp_tr || std::is_same_v<K, key_type>, size_type>
count(const K &x) const {
if constexpr (!IsMulti) {
return find(x) != end() ? 1 : 0;
return contains(x) ? 1 : 0;
}

if constexpr (IsOrdered) {
Expand All @@ -925,7 +925,7 @@ namespace small::detail {
template <typename K>
std::enable_if_t<is_comp_tr || std::is_same_v<K, key_type>, bool>
contains(const K &x) const {
return count(x) > 0;
return find(x) != end();
}

/// \brief Check if elements with a given key exists
Expand Down

0 comments on commit 10086fc

Please sign in to comment.