mirror of
https://github.com/matrix-construct/construct
synced 2024-12-27 07:54:05 +01:00
ircd::buffer: Add an alignment check util.
This commit is contained in:
parent
adf2de8aed
commit
26ed0ee0e4
1 changed files with 11 additions and 0 deletions
|
@ -65,6 +65,7 @@ namespace ircd::buffer
|
||||||
template<class it> bool operator!(const buffer<it> &buffer);
|
template<class it> bool operator!(const buffer<it> &buffer);
|
||||||
template<class it> size_t size(const buffer<it> &buffer);
|
template<class it> size_t size(const buffer<it> &buffer);
|
||||||
template<class it> const it &data(const buffer<it> &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> size_t consume(buffer<it> &buffer, const size_t &bytes);
|
template<class it> size_t consume(buffer<it> &buffer, const size_t &bytes);
|
||||||
template<class it> buffer<it> operator+(const buffer<it> &buffer, const size_t &bytes);
|
template<class it> buffer<it> operator+(const buffer<it> &buffer, const size_t &bytes);
|
||||||
template<class it> it copy(it &dest, const it &stop, const const_buffer &);
|
template<class it> it copy(it &dest, const it &stop, const const_buffer &);
|
||||||
|
@ -348,6 +349,16 @@ ircd::buffer::consume(buffer<it> &buffer,
|
||||||
return size(buffer);
|
return size(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class it>
|
||||||
|
bool
|
||||||
|
ircd::buffer::aligned(const buffer<it> &buffer,
|
||||||
|
const size_t &a)
|
||||||
|
{
|
||||||
|
return likely(a)?
|
||||||
|
uintptr_t(data(buffer)) % a == 0 && size(buffer) % a == 0:
|
||||||
|
true;
|
||||||
|
}
|
||||||
|
|
||||||
template<class it>
|
template<class it>
|
||||||
const it &
|
const it &
|
||||||
ircd::buffer::data(const buffer<it> &buffer)
|
ircd::buffer::data(const buffer<it> &buffer)
|
||||||
|
|
Loading…
Reference in a new issue