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 <[email protected]>
  • Loading branch information
MiguelCompany committed Feb 14, 2025
1 parent 8c7fc72 commit 44f0324
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <fastdds/rtps/common/LocatorList.hpp>
#include <fastdds/rtps/history/WriterHistory.hpp>
#include <fastdds/rtps/transport/NetworkBuffer.hpp>
#include <fastdds/utils/collections/ResourceLimitedVector.hpp>
#include <fastdds/utils/TimedMutex.hpp>

#include <rtps/builtin/data/ReaderProxyData.hpp>
Expand All @@ -47,6 +48,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 +133,8 @@ 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 interested_readers_.end() !=
std::find(interested_readers_.begin(), interested_readers_.end(), reader_guid);
}

void PDPStatelessWriter::mark_all_readers_interested()
Expand All @@ -150,16 +153,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_.emplace_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 @@ -20,10 +20,10 @@
#define FASTDDS_RTPS_BUILTIN_DISCOVERY_PARTICIPANT_SIMPLE__PDPSTATELESSWRITER_HPP

#include <chrono>
#include <set>

#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 +141,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 44f0324

Please sign in to comment.