mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 15:33:54 +01:00
ircd::buffer: Always inline fundamental buffer template utils.
This commit is contained in:
parent
bc82a5a12c
commit
c3b6bba288
5 changed files with 40 additions and 14 deletions
|
@ -217,6 +217,7 @@ ircd::buffer::operator<<(std::ostream &s, const buffer<it> &buffer)
|
|||
// to ensure cross-platform guarantees the zero'ing doesn't get optimized away.
|
||||
#ifndef HAVE_SODIUM_H
|
||||
inline size_t
|
||||
__attribute__((always_inline))
|
||||
ircd::buffer::zero(const mutable_buffer &buf)
|
||||
{
|
||||
std::memset(data(buf), 0x0, size(buf));
|
||||
|
@ -225,12 +226,14 @@ ircd::buffer::zero(const mutable_buffer &buf)
|
|||
#endif
|
||||
|
||||
inline void
|
||||
__attribute__((always_inline))
|
||||
ircd::buffer::reverse(const mutable_buffer &buf)
|
||||
{
|
||||
std::reverse(data(buf), data(buf) + size(buf));
|
||||
}
|
||||
|
||||
inline size_t
|
||||
__attribute__((always_inline))
|
||||
ircd::buffer::reverse(const mutable_buffer &dst,
|
||||
const const_buffer &src)
|
||||
{
|
||||
|
@ -266,6 +269,7 @@ ircd::buffer::copy(const mutable_buffer &dst,
|
|||
}
|
||||
|
||||
inline size_t
|
||||
__attribute__((always_inline))
|
||||
ircd::buffer::move(const mutable_buffer &dst,
|
||||
const const_buffer &src)
|
||||
{
|
||||
|
@ -276,6 +280,7 @@ ircd::buffer::move(const mutable_buffer &dst,
|
|||
}
|
||||
|
||||
inline size_t
|
||||
__attribute__((always_inline))
|
||||
ircd::buffer::copy(const mutable_buffer &dst,
|
||||
const const_buffer &src)
|
||||
{
|
||||
|
@ -286,8 +291,8 @@ ircd::buffer::copy(const mutable_buffer &dst,
|
|||
}
|
||||
|
||||
template<class it>
|
||||
it
|
||||
__attribute__((stack_protect))
|
||||
inline it
|
||||
__attribute__((always_inline))
|
||||
ircd::buffer::move(it &dest,
|
||||
const it &stop,
|
||||
const const_buffer &src)
|
||||
|
@ -307,8 +312,8 @@ ircd::buffer::move(it &dest,
|
|||
}
|
||||
|
||||
template<class it>
|
||||
it
|
||||
__attribute__((stack_protect))
|
||||
inline it
|
||||
__attribute__((always_inline))
|
||||
ircd::buffer::copy(it &dest,
|
||||
const it &stop,
|
||||
const const_buffer &src)
|
||||
|
@ -328,7 +333,8 @@ ircd::buffer::copy(it &dest,
|
|||
}
|
||||
|
||||
template<class it>
|
||||
ircd::buffer::buffer<it>
|
||||
inline ircd::buffer::buffer<it>
|
||||
__attribute__((always_inline))
|
||||
ircd::buffer::operator+(const buffer<it> &buffer,
|
||||
const size_t &bytes)
|
||||
{
|
||||
|
@ -344,7 +350,8 @@ ircd::buffer::operator+(const buffer<it> &buffer,
|
|||
}
|
||||
|
||||
template<class it>
|
||||
size_t
|
||||
inline size_t
|
||||
__attribute__((always_inline))
|
||||
ircd::buffer::consume(buffer<it> &buffer,
|
||||
const size_t &bytes)
|
||||
{
|
||||
|
@ -366,14 +373,16 @@ ircd::buffer::aligned(const buffer<it> &buffer,
|
|||
}
|
||||
|
||||
template<class it>
|
||||
const it &
|
||||
inline const it &
|
||||
__attribute__((always_inline))
|
||||
ircd::buffer::data(const buffer<it> &buffer)
|
||||
{
|
||||
return get<0>(buffer);
|
||||
}
|
||||
|
||||
template<class it>
|
||||
size_t
|
||||
inline size_t
|
||||
__attribute__((always_inline))
|
||||
ircd::buffer::size(const buffer<it> &buffer)
|
||||
{
|
||||
assert(get<0>(buffer) <= get<1>(buffer));
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
///
|
||||
template<class it>
|
||||
struct ircd::buffer::buffer
|
||||
:std::tuple<it, it>
|
||||
:std::pair<it, it>
|
||||
{
|
||||
using iterator = it;
|
||||
using value_type = typename std::remove_pointer<iterator>::type;
|
||||
|
@ -42,23 +42,27 @@ struct ircd::buffer::buffer
|
|||
};
|
||||
|
||||
template<class it>
|
||||
inline __attribute__((always_inline))
|
||||
ircd::buffer::buffer<it>::buffer()
|
||||
:buffer{nullptr, nullptr}
|
||||
{}
|
||||
|
||||
template<class it>
|
||||
inline __attribute__((always_inline))
|
||||
ircd::buffer::buffer<it>::buffer(const it &start,
|
||||
const size_t &size)
|
||||
:buffer{start, start + size}
|
||||
{}
|
||||
|
||||
template<class it>
|
||||
inline __attribute__((always_inline, flatten))
|
||||
ircd::buffer::buffer<it>::buffer(const it &start,
|
||||
const it &stop)
|
||||
:std::tuple<it, it>{start, stop}
|
||||
:std::pair<it, it>{start, stop}
|
||||
{}
|
||||
|
||||
template<class it>
|
||||
inline __attribute__((always_inline, flatten))
|
||||
ircd::buffer::buffer<it>::operator string_view()
|
||||
const
|
||||
{
|
||||
|
|
|
@ -31,31 +31,37 @@ struct ircd::buffer::const_buffer
|
|||
};
|
||||
|
||||
inline
|
||||
__attribute__((always_inline))
|
||||
ircd::buffer::const_buffer::const_buffer(const buffer<const char *> &b)
|
||||
:buffer<const char *>{b}
|
||||
{}
|
||||
|
||||
inline
|
||||
__attribute__((always_inline))
|
||||
ircd::buffer::const_buffer::const_buffer(const buffer<char *> &b)
|
||||
:buffer<const char *>{data(b), size(b)}
|
||||
{}
|
||||
|
||||
inline
|
||||
__attribute__((always_inline))
|
||||
ircd::buffer::const_buffer::const_buffer(const mutable_buffer &b)
|
||||
:buffer<const char *>{data(b), size(b)}
|
||||
{}
|
||||
|
||||
inline
|
||||
__attribute__((always_inline))
|
||||
ircd::buffer::const_buffer::const_buffer(const string_view &s)
|
||||
:buffer<const char *>{data(s), size(s)}
|
||||
{}
|
||||
|
||||
template<size_t SIZE>
|
||||
inline __attribute__((always_inline))
|
||||
ircd::buffer::const_buffer::const_buffer(const char (&buf)[SIZE])
|
||||
:buffer<const char *>{buf, SIZE}
|
||||
{}
|
||||
|
||||
template<size_t SIZE>
|
||||
inline __attribute__((always_inline))
|
||||
ircd::buffer::const_buffer::const_buffer(const std::array<char, SIZE> &buf)
|
||||
:buffer<const char *>{reinterpret_cast<const char *>(buf.data()), SIZE}
|
||||
{}
|
||||
|
|
|
@ -36,6 +36,7 @@ struct ircd::buffer::mutable_buffer
|
|||
};
|
||||
|
||||
inline
|
||||
__attribute__((always_inline))
|
||||
ircd::buffer::mutable_buffer::mutable_buffer(const buffer<char *> &b)
|
||||
:buffer<char *>{b}
|
||||
{}
|
||||
|
@ -43,22 +44,26 @@ ircd::buffer::mutable_buffer::mutable_buffer(const buffer<char *> &b)
|
|||
/// lvalue string reference offered to write through to a std::string as
|
||||
/// the buffer. should be hard to bind by accident...
|
||||
inline
|
||||
__attribute__((always_inline))
|
||||
ircd::buffer::mutable_buffer::mutable_buffer(std::string &buf)
|
||||
:mutable_buffer{const_cast<char *>(buf.data()), buf.size()}
|
||||
{}
|
||||
|
||||
inline
|
||||
__attribute__((always_inline))
|
||||
ircd::buffer::mutable_buffer::mutable_buffer(const std::function<void (const mutable_buffer &)> &closure)
|
||||
{
|
||||
closure(*this);
|
||||
}
|
||||
|
||||
template<size_t SIZE>
|
||||
inline __attribute__((always_inline, gnu_inline))
|
||||
ircd::buffer::mutable_buffer::mutable_buffer(char (&buf)[SIZE])
|
||||
:buffer<char *>{buf, SIZE}
|
||||
{}
|
||||
|
||||
template<size_t SIZE>
|
||||
inline __attribute__((always_inline))
|
||||
ircd::buffer::mutable_buffer::mutable_buffer(std::array<char, SIZE> &buf)
|
||||
:buffer<char *>{buf.data(), SIZE}
|
||||
{}
|
||||
|
|
|
@ -156,16 +156,18 @@ struct ircd::string_view
|
|||
{}
|
||||
|
||||
// (non-standard) our array based constructor
|
||||
template<size_t SIZE>
|
||||
constexpr string_view(const std::array<char, SIZE> &array)
|
||||
template<size_t SIZE> constexpr
|
||||
__attribute__((always_inline))
|
||||
string_view(const std::array<char, SIZE> &array)
|
||||
:string_view
|
||||
{
|
||||
array.data(), std::find(array.begin(), array.end(), '\0')
|
||||
}{}
|
||||
|
||||
// (non-standard) our buffer based constructor
|
||||
template<size_t SIZE>
|
||||
constexpr string_view(const char (&buf)[SIZE])
|
||||
template<size_t SIZE> constexpr
|
||||
__attribute__((always_inline))
|
||||
string_view(const char (&buf)[SIZE])
|
||||
:string_view
|
||||
{
|
||||
buf, std::find(buf, buf + SIZE, '\0')
|
||||
|
|
Loading…
Reference in a new issue