0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 18:22:50 +01:00

ircd::buffer: Branchfree copy overload for single character.

This commit is contained in:
Jason Volk 2020-04-13 22:30:34 -07:00
parent 66be4ba6c3
commit b2795c0338

View file

@ -80,8 +80,10 @@ namespace ircd::buffer
// Single buffer mutators
template<class it> size_t consume(buffer<it> &buffer, const size_t &bytes);
template<class it> buffer<it> &operator+=(buffer<it> &buffer, const size_t &bytes);
char *&copy(char *&dest, char *const &stop, char src);
char *&copy(char *&dest, char *const &stop, const const_buffer &src);
char *&move(char *&dest, char *const &stop, const const_buffer &src);
size_t copy(const mutable_buffer &dst, const char src);
size_t copy(const mutable_buffer &dst, const const_buffer &src);
size_t move(const mutable_buffer &dst, const const_buffer &src);
template<size_t SIZE> size_t copy(const mutable_buffer &dst, const char (&)[SIZE]);
@ -311,6 +313,16 @@ ircd::buffer::copy(const mutable_buffer &dst,
return std::distance(s, e);
}
inline size_t
ircd::buffer::copy(const mutable_buffer &dst,
const char src)
{
char *const &s(begin(dst)), *e(s);
e = copy(e, end(dst), src);
assert(std::distance(s, e) >= 0);
return std::distance(s, e);
}
inline char *&
ircd::buffer::move(char *&dest,
char *const &stop,
@ -344,6 +356,19 @@ ircd::buffer::copy(char *&dest,
return dest;
}
inline char *&
ircd::buffer::copy(char *&dest,
char *const &stop,
char src)
{
assert(dest <= stop);
const bool cpsz(dest != stop);
(cpsz? *dest : src) = src;
dest += cpsz;
assert(dest <= stop);
return dest;
}
template<class it>
inline ircd::buffer::buffer<it> &
__attribute__((always_inline))