Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions source/common/common/mem_block_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ template <class T> class MemBlockBuilder {

/**
* Populates (or repopulates) the MemBlockBuilder to make it the specified
* capacity. This does not have resize semantics; when populate() is called any
* previous contents are erased.
* capacity. This does not have resize semantics; when populate() is called
Comment thread
jmarantz marked this conversation as resolved.
Outdated
* any previous contents are erased.
*
* @param capacity The number of memory elements to allocate.
*/
Expand Down Expand Up @@ -96,7 +96,7 @@ template <class T> class MemBlockBuilder {
* @return the transferred storage.
*/
std::unique_ptr<T[]> release() {
write_span_.reset();
write_span_ = absl::MakeSpan(static_cast<T*>(nullptr), 0);
return std::move(data_);
}

Expand Down
9 changes: 7 additions & 2 deletions test/common/common/mem_block_builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ TEST(MemBlockBuilderTest, AppendUint8) {

append.appendBlock(mem_block);
EXPECT_EQ(0, append.capacityRemaining());
EXPECT_EQ((std::vector<uint8_t>{8, 9, 5, 6, 7, 8, 9}), append.span());
uint64_t size = append.size();
std::unique_ptr<uint8_t[]> data = append.release();
EXPECT_EQ((std::vector<uint8_t>{8, 9, 5, 6, 7, 8, 9}),
std::vector<uint8_t>(data.get(), data.get() + size));

mem_block.reset();
EXPECT_EQ(0, mem_block.capacity());
Expand Down Expand Up @@ -56,8 +59,10 @@ TEST(MemBlockBuilderTest, AppendUint32) {

append.appendBlock(mem_block);
EXPECT_EQ(0, append.capacityRemaining());
uint64_t size = append.size();
std::unique_ptr<uint32_t[]> data = append.release();
EXPECT_EQ((std::vector<uint32_t>{100008, 100009, 100005, 100006, 100007, 100008, 100009}),
append.span());
std::vector<uint32_t>(data.get(), data.get() + size));

mem_block.reset();
EXPECT_EQ(0, mem_block.capacity());
Expand Down