32 #undef ELECTRONEUM_DEFAULT_LOG_CATEGORY 33 #define ELECTRONEUM_DEFAULT_LOG_CATEGORY "net.buffer" 42 const size_t capacity = storage.capacity();
43 const size_t avail = capacity - storage.size();
51 const bool move =
size() + sz <= capacity;
54 const size_t bytes = storage.size() - offset;
55 NET_BUFFER_LOG(
"appending " << sz <<
" from " <<
size() <<
" by moving " << bytes <<
" from offset " << offset <<
" first (forced)");
56 memmove(storage.data(), storage.data() + offset, bytes);
57 storage.resize(bytes);
63 std::vector<uint8_t> new_storage;
64 size_t reserve = (((
size() + sz) * 3 / 2) + 4095) & ~4095;
65 new_storage.reserve(reserve);
66 new_storage.resize(
size());
68 memcpy(new_storage.data(), storage.data() + offset, storage.size() - offset);
70 std::swap(storage, new_storage);
76 if (
size() <= 4096 && offset > 4096 * 16 && offset >= capacity / 2)
79 const size_t pos = storage.size() - offset;
80 NET_BUFFER_LOG(
"appending " << sz <<
" from " <<
size() <<
" by moving " << pos <<
" from offset " << offset <<
" first (unforced)");
81 memmove(storage.data(), storage.data() + offset, storage.size() - offset);
87 NET_BUFFER_LOG(
"appending " << sz <<
" from " <<
size() <<
" by writing to existing capacity");
92 storage.insert(storage.end(), (
const uint8_t*)data, (
const uint8_t*)data + sz);
94 NET_BUFFER_LOG(
"storage now " << offset <<
"/" << storage.size() <<
"/" << storage.capacity());
void append(const void *data, size_t sz)
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
#define NET_BUFFER_LOG(x)
const T & move(const T &t)
void * memcpy(void *a, const void *b, size_t c)
void * memmove(void *a, const void *b, size_t c)