[algs] Implement swap() for pair_t

Helps priority_queue::pop_minimum and friends, which help subsetter
repacker. Shows a few percentage improvement on NotoNastaliq benchmark.
This commit is contained in:
Behdad Esfahbod 2022-11-21 19:14:03 -07:00
parent a2984a2932
commit 35878df215
1 changed files with 18 additions and 11 deletions

View File

@ -484,6 +484,17 @@ struct
} }
HB_FUNCOBJ (hb_equal); HB_FUNCOBJ (hb_equal);
struct
{
template <typename T> void
operator () (T& a, T& b) const
{
using std::swap; // allow ADL
swap (a, b);
}
}
HB_FUNCOBJ (hb_swap);
template <typename T1, typename T2> template <typename T1, typename T2>
struct hb_pair_t struct hb_pair_t
@ -513,6 +524,13 @@ struct hb_pair_t
bool operator > (const pair_t& o) const { return first > o.first || (first == o.first && second > o.second); } bool operator > (const pair_t& o) const { return first > o.first || (first == o.first && second > o.second); }
bool operator <= (const pair_t& o) const { return !(*this > o); } bool operator <= (const pair_t& o) const { return !(*this > o); }
friend void swap (hb_pair_t& a, hb_pair_t& b)
{
hb_swap (a.first, b.first);
hb_swap (a.second, b.second);
}
T1 first; T1 first;
T2 second; T2 second;
}; };
@ -559,17 +577,6 @@ struct
} }
HB_FUNCOBJ (hb_clamp); HB_FUNCOBJ (hb_clamp);
struct
{
template <typename T> void
operator () (T& a, T& b) const
{
using std::swap; // allow ADL
swap (a, b);
}
}
HB_FUNCOBJ (hb_swap);
/* /*
* Bithacks. * Bithacks.
*/ */