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