Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions core/io/mcbp_parser.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,24 @@ mcbp_parser::next(mcbp_message& msg)
key_size = static_cast<std::uint32_t>(msg.header.keylen >> 8U);
prefix_size = static_cast<std::uint32_t>(framing_extras_size) + static_cast<std::uint32_t>(msg.header.extlen) + key_size;
}
std::copy(buf.begin() + header_size, buf.begin() + header_size + prefix_size, std::back_insert_iterator(msg.body));
msg.body.insert(msg.body.end(), buf.begin() + header_size, buf.begin() + header_size + prefix_size);

bool is_compressed = (msg.header.datatype & static_cast<std::uint8_t>(protocol::datatype::snappy)) != 0;
bool use_raw_value = true;
if (is_compressed) {
std::string uncompressed;
std::size_t offset = header_size + prefix_size;
if (snappy::Uncompress(reinterpret_cast<const char*>(buf.data() + offset), body_size - prefix_size, &uncompressed)) {
std::transform(uncompressed.begin(), uncompressed.end(), std::back_insert_iterator(msg.body), [](auto ch) {
return static_cast<std::byte>(ch);
});
msg.body.insert(msg.body.end(),
reinterpret_cast<std::byte*>(&uncompressed.data()[0]),
reinterpret_cast<std::byte*>(&uncompressed.data()[uncompressed.size()]));
use_raw_value = false;
// patch header with new body size
msg.header.bodylen = utils::byte_swap(static_cast<std::uint32_t>(prefix_size + uncompressed.size()));
}
}
if (use_raw_value) {
std::copy(buf.begin() + header_size + prefix_size, buf.begin() + header_size + body_size, std::back_insert_iterator(msg.body));
msg.body.insert(msg.body.end(), buf.begin() + header_size + prefix_size, buf.begin() + header_size + body_size);
}
buf.erase(buf.begin(), buf.begin() + header_size + body_size);
if (!buf.empty() && !protocol::is_valid_magic(std::to_integer<std::uint8_t>(buf[0]))) {
Expand Down
2 changes: 1 addition & 1 deletion core/io/mcbp_parser.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct mcbp_parser {
void feed(Iterator begin, Iterator end)
{
buf.reserve(buf.size() + static_cast<std::size_t>(std::distance(begin, end)));
std::copy(begin, end, std::back_insert_iterator(buf));
buf.insert(buf.end(), begin, end);
}

void reset()
Expand Down
4 changes: 2 additions & 2 deletions core/utils/json.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ class to_byte_vector
void write(tao::binary_view data)
{
buffer_.reserve(buffer_.size() + data.size());
std::copy(data.begin(), data.end(), std::back_inserter(buffer_));
buffer_.insert(buffer_.end(), data.begin(), data.end());
}

void write(std::string_view data)
{
buffer_.reserve(buffer_.size() + data.size());
std::transform(data.begin(), data.end(), std::back_inserter(buffer_), [](auto ch) { return static_cast<std::byte>(ch); });
buffer_.insert(buffer_.end(), reinterpret_cast<const std::byte*>(&data[0]), reinterpret_cast<const std::byte*>(&data[data.size()]));
}

inline void escape(const std::string_view s)
Expand Down