Skip to content

Commit

Permalink
Allocate vector of correct size right away when constructing Chunks.
Browse files Browse the repository at this point in the history
  • Loading branch information
bbannier committed Dec 1, 2023
1 parent c52d307 commit 43880db
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions hilti/runtime/src/types/stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ Chunk::Chunk(const Offset& offset, const View& d) : _offset(offset) {
_data = std::make_pair(d.size(), a);
}
else {
std::vector<Byte> v;
v.resize(d.size());
std::vector<Byte> v(d.size());
d.copyRaw(v.data());
_data = std::move(v);
}
Expand All @@ -40,8 +39,7 @@ Chunk::Chunk(const Offset& offset, std::string_view s) : _offset(offset) {
_data = std::make_pair(s.size(), a);
}
else {
std::vector<Byte> v;
v.resize(s.size());
std::vector<Byte> v(s.size());
memcpy(v.data(), s.data(), s.size());
_data = std::move(v);
}
Expand Down

0 comments on commit 43880db

Please sign in to comment.