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
3 changes: 3 additions & 0 deletions src/rpp/rpp/operators/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ namespace rpp::operators::details
m_bucket.push_back(std::forward<T>(v));
if (m_bucket.size() == m_bucket.capacity())
{
const auto capacity = m_bucket.capacity();
m_observer.on_next(std::move(m_bucket));

m_bucket.clear();
m_bucket.reserve(capacity);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it matter? I though clear doesn't relinquish memory unless you shrink_to_fit

@AlexInLog AlexInLog Aug 19, 2024

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was expecting the same but in case of moving vector out it actually also moves-out capacity/size
https://godbolt.org/z/1fhhYW1xP

}
}

Expand Down
12 changes: 12 additions & 0 deletions src/tests/rpp/test_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ TEST_CASE("buffer bundles items")
| rpp::ops::subscribe(mock);
}
}
SECTION("accept by moving")
{
REQUIRE_CALL(*mock, on_next_rvalue(std::vector{1, 2})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next_rvalue(std::vector{3, 4})).IN_SEQUENCE(s);

rpp::source::just(1, 2, 3, 4)
| rpp::ops::buffer(2)
| rpp::ops::subscribe([&mock](std::vector<int> b) // NOLINT
{
mock.on_next(std::move(b));
});
}
}

TEST_CASE("buffer satisfies disposable contracts")
Expand Down