Skip to content

Commit

Permalink
Refs #22708. Avoid allocations using a ResourceLimitedVector instea…
Browse files Browse the repository at this point in the history
…d of an `std::set`

Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
  • Loading branch information
MiguelCompany committed Jan 28, 2025
1 parent 633530a commit 490687a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ PDPStatelessWriter::PDPStatelessWriter(
WriterHistory* history,
WriterListener* listener)
: StatelessWriter(participant, guid, attributes, flow_controller, history, listener)
, interested_readers_(participant->get_attributes().allocation.participants)
{
}

Expand Down Expand Up @@ -131,7 +132,7 @@ bool PDPStatelessWriter::is_relevant(
const fastdds::rtps::CacheChange_t& /* change */,
const fastdds::rtps::GUID_t& reader_guid) const
{
return interested_readers_.count(reader_guid) > 0;
return std::find(interested_readers_.begin(), interested_readers_.end(), reader_guid) != interested_readers_.end();
}

void PDPStatelessWriter::mark_all_readers_interested()
Expand All @@ -150,16 +151,20 @@ void PDPStatelessWriter::add_interested_reader(
std::lock_guard<RecursiveTimedMutex> guard(mp_mutex);
if (!should_reach_all_destinations_)
{
interested_readers_.insert(reader_guid);
reader_data_filter(this);
auto it = std::find(interested_readers_.begin(), interested_readers_.end(), reader_guid);
if (it == interested_readers_.end())
{
interested_readers_.push_back(reader_guid);
reader_data_filter(this);
}
}
}

void PDPStatelessWriter::remove_interested_reader(
const GUID_t& reader_guid)
{
std::lock_guard<RecursiveTimedMutex> guard(mp_mutex);
interested_readers_.erase(reader_guid);
interested_readers_.remove(reader_guid);
}

void PDPStatelessWriter::reschedule_all_samples()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <fastdds/rtps/common/LocatorList.hpp>
#include <fastdds/rtps/interfaces/IReaderDataFilter.hpp>
#include <fastdds/utils/collections/ResourceLimitedVector.hpp>

#include <rtps/writer/StatelessWriter.hpp>

Expand Down Expand Up @@ -141,7 +142,7 @@ class PDPStatelessWriter : public StatelessWriter, private IReaderDataFilter
//! Configured initial peers
LocatorList initial_peers_{};
//! The set of readers interested
mutable std::set<GUID_t> interested_readers_{};
mutable ResourceLimitedVector<GUID_t> interested_readers_;
//! Whether we have set that all destinations are interested
mutable bool should_reach_all_destinations_ = false;

Expand Down

0 comments on commit 490687a

Please sign in to comment.