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
6 changes: 2 additions & 4 deletions src/messages/peer/detail/get_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <bitcoin/network/messages/peer/detail/get_data.hpp>

#include <algorithm>
#include <ranges>
#include <bitcoin/network/messages/peer/enums/identifier.hpp>
#include <bitcoin/network/messages/peer/enums/level.hpp>
#include <bitcoin/network/messages/peer/enums/magic_numbers.hpp>
Expand Down Expand Up @@ -93,13 +92,12 @@ size_t get_data::size(uint32_t version) const NOEXCEPT
(items.size() * item::size(version));
}

// Populated in reverse order for efficient removals.
inventory_items get_data::select(selector types) const NOEXCEPT
{
inventory_items out{};
out.reserve(count(types));
for (const auto& item: std::views::reverse(items))

for (const auto& item: items)
if (item.is_selected(types))
out.push_back(item);

Expand Down
4 changes: 1 addition & 3 deletions src/messages/peer/detail/inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <bitcoin/network/messages/peer/detail/inventory.hpp>

#include <algorithm>
#include <ranges>
#include <utility>
#include <bitcoin/network/messages/peer/enums/identifier.hpp>
#include <bitcoin/network/messages/peer/enums/level.hpp>
Expand Down Expand Up @@ -123,13 +122,12 @@ size_t inventory::size(uint32_t version) const NOEXCEPT
(items.size() * item::size(version));
}

// Populated in reverse order for efficient removals.
inventory_items inventory::select(selector types) const NOEXCEPT
{
inventory_items out{};
out.reserve(count(types));

for (const auto& item: std::views::reverse(items))
for (const auto& item: items)
if (item.is_selected(types))
out.push_back(item);

Expand Down
8 changes: 4 additions & 4 deletions test/messages/peer/detail/get_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ BOOST_AUTO_TEST_CASE(get_data__select__selectors__expected_items)

const auto txs = inv.select(inventory_item::selector::txids);
BOOST_REQUIRE_EQUAL(txs.size(), 2u);
BOOST_CHECK(txs[0].type == inventory_item::type_id::witness_tx);
BOOST_CHECK(txs[1].type == inventory_item::type_id::transaction);
BOOST_CHECK(txs[0].type == inventory_item::type_id::transaction);
BOOST_CHECK(txs[1].type == inventory_item::type_id::witness_tx);

const auto wtxs = inv.select(inventory_item::selector::wtxids);
BOOST_REQUIRE_EQUAL(wtxs.size(), 1u);
BOOST_CHECK(wtxs[0].type == inventory_item::type_id::wtxid);

const auto blocks = inv.select(inventory_item::selector::blocks);
BOOST_REQUIRE_EQUAL(blocks.size(), 2u);
BOOST_CHECK(blocks[0].type == inventory_item::type_id::witness_block);
BOOST_CHECK(blocks[1].type == inventory_item::type_id::block);
BOOST_CHECK(blocks[0].type == inventory_item::type_id::block);
BOOST_CHECK(blocks[1].type == inventory_item::type_id::witness_block);

const auto filters = inv.select(inventory_item::selector::filters);
BOOST_REQUIRE_EQUAL(filters.size(), 1u);
Expand Down
8 changes: 4 additions & 4 deletions test/messages/peer/detail/inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ BOOST_AUTO_TEST_CASE(inventory__select__selectors__expected_items)

const auto txs = inv.select(inventory_item::selector::txids);
BOOST_REQUIRE_EQUAL(txs.size(), 2u);
BOOST_CHECK(txs[0].type == inventory_item::type_id::witness_tx);
BOOST_CHECK(txs[1].type == inventory_item::type_id::transaction);
BOOST_CHECK(txs[0].type == inventory_item::type_id::transaction);
BOOST_CHECK(txs[1].type == inventory_item::type_id::witness_tx);

const auto wtxs = inv.select(inventory_item::selector::wtxids);
BOOST_REQUIRE_EQUAL(wtxs.size(), 1u);
BOOST_CHECK(wtxs[0].type == inventory_item::type_id::wtxid);

const auto blocks = inv.select(inventory_item::selector::blocks);
BOOST_REQUIRE_EQUAL(blocks.size(), 2u);
BOOST_CHECK(blocks[0].type == inventory_item::type_id::witness_block);
BOOST_CHECK(blocks[1].type == inventory_item::type_id::block);
BOOST_CHECK(blocks[0].type == inventory_item::type_id::block);
BOOST_CHECK(blocks[1].type == inventory_item::type_id::witness_block);

const auto filters = inv.select(inventory_item::selector::filters);
BOOST_REQUIRE_EQUAL(filters.size(), 1u);
Expand Down