Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Sep 18, 2024
1 parent 78a71ab commit fff8bb3
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions include/ylt/standalone/iguana/pb_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,23 @@ IGUANA_INLINE void from_pb_impl(T& val, std::string_view& pb_str,
throw std::invalid_argument(
"Invalid fixed int value: too few bytes.");
}
using item_type = typename T::value_type;
size_t start = pb_str.size();
if constexpr (is_fixed_v<item_type>) {
int num = size / sizeof(item_type);
int old_size = val.size();
detail::resize(val, old_size + num);
std::memcpy(val.data() + old_size, pb_str.data(), size);
pb_str = pb_str.substr(size);
}
else {
size_t start = pb_str.size();

while (!pb_str.empty()) {
item_type item;
from_pb_impl(item, pb_str);
val.push_back(std::move(item));
if (start - pb_str.size() == size) {
break;
while (!pb_str.empty()) {
item_type item;
from_pb_impl(item, pb_str);
val.push_back(std::move(item));
if (start - pb_str.size() == size) {
break;
}
}
}
}
Expand Down

0 comments on commit fff8bb3

Please sign in to comment.