0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-19 00:10:59 +01:00

ircd::buffer: Improve the overlap tool.

This commit is contained in:
Jason Volk 2020-06-06 15:48:32 -07:00
parent 0da425590b
commit 6e1d58c2e6

View file

@ -75,6 +75,7 @@ namespace ircd::buffer
template<class it> const it &data(const buffer<it> &buffer);
template<class it> bool aligned(const buffer<it> &buffer, const size_t &alignment);
template<class it> buffer<it> operator+(const buffer<it> &buffer, const size_t &bytes);
size_t overlap_count(const const_buffer &, const const_buffer &);
bool overlap(const const_buffer &, const const_buffer &);
// Single buffer mutators
@ -408,8 +409,21 @@ __attribute__((always_inline))
ircd::buffer::overlap(const const_buffer &a,
const const_buffer &b)
{
return data(a) + size(a) > data(b) &&
data(a) + size(a) < data(b) + size(b);
return overlap_count(a, b) > 0UL;
}
inline size_t
__attribute__((always_inline))
ircd::buffer::overlap_count(const const_buffer &a,
const const_buffer &b)
{
const char *const res[2]
{
std::max(begin(a), begin(b)),
std::min(end(a), end(b)),
};
return std::max(res[1] - res[0], 0L);
}
template<class it>