mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 02:02:38 +01:00
ircd::db: Optimize iterator comparison operators.
This commit is contained in:
parent
2741ab785c
commit
7201a11c7a
1 changed files with 25 additions and 6 deletions
31
ircd/db.cc
31
ircd/db.cc
|
@ -7407,24 +7407,43 @@ bool
|
|||
ircd::db::operator!=(const column::const_iterator_base &a, const column::const_iterator_base &b)
|
||||
noexcept
|
||||
{
|
||||
return !(a == b);
|
||||
const uint operands
|
||||
{
|
||||
uint(bool(a)) +
|
||||
uint(bool(b))
|
||||
};
|
||||
|
||||
// Two invalid iterators are equal; one invalid iterator is not.
|
||||
if(likely(operands <= 1))
|
||||
return operands == 1;
|
||||
|
||||
// Two valid iterators are compared
|
||||
assert(operands == 2);
|
||||
const auto &ak(a.it->key());
|
||||
const auto &bk(b.it->key());
|
||||
return ak.compare(bk) != 0;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::db::operator==(const column::const_iterator_base &a, const column::const_iterator_base &b)
|
||||
noexcept
|
||||
{
|
||||
if(a && b)
|
||||
const uint operands
|
||||
{
|
||||
uint(bool(a)) +
|
||||
uint(bool(b))
|
||||
};
|
||||
|
||||
// Two valid iterators are compared
|
||||
if(likely(operands > 1))
|
||||
{
|
||||
const auto &ak(a.it->key());
|
||||
const auto &bk(b.it->key());
|
||||
return ak.compare(bk) == 0;
|
||||
}
|
||||
|
||||
if(!a && !b)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
// Two invalid iterators are equal; one invalid iterator is not.
|
||||
return operands == 0;
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
Loading…
Reference in a new issue