Skip to content

Commit

Permalink
feat(io): Inline prepare buffer function
Browse files Browse the repository at this point in the history
SDB-6763
  • Loading branch information
markaylett committed Mar 18, 2024
1 parent 5b31297 commit ccc3957
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
12 changes: 0 additions & 12 deletions toolbox/io/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,6 @@ void Buffer::consume(std::size_t count) noexcept
}
}

MutableBuffer Buffer::prepare(std::size_t size)
{
auto avail = available();
if (size > avail) {
// More buffer space required.
const auto diff = size - avail;
buf_.resize(buf_.size() + diff);
avail = size;
}
return {wptr(), avail};
}

ConstBuffer advance(ConstBuffer buf, std::size_t n) noexcept
{
const auto* const data = buffer_cast<const char*>(buf);
Expand Down
12 changes: 11 additions & 1 deletion toolbox/io/Buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,17 @@ class TOOLBOX_API Buffer {
void consume(std::size_t count) noexcept;

/// Returns write buffer of at least size bytes.
MutableBuffer prepare(std::size_t size);
MutableBuffer prepare(std::size_t size)
{
auto avail = available();
if (size > avail) {
// More buffer space required.
const auto diff = size - avail;
buf_.resize(buf_.size() + diff);
avail = size;
}
return {wptr(), avail};
}

/// Reserve storage.
void reserve(std::size_t capacity) { buf_.reserve(capacity); }
Expand Down

0 comments on commit ccc3957

Please # to comment.