Skip to content

Commit

Permalink
remove duplicate types
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 committed Oct 11, 2024
1 parent 0da35a8 commit ea75328
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions core/src/MessageFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*
*/

#include <unordered_set>

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4146 4251)
Expand Down Expand Up @@ -65,11 +67,6 @@ MessageFactory::MessagePtr MessageFactory::New(
{
type = kGzMsgsPrefix + _msgType.substr(9);
}
// Convert ".gz.msgs." prefix
else if (_msgType.find(".gz.msgs.") == 0)
{
type = kGzMsgsPrefix + _msgType.substr(9);
}
else
{
type = _msgType;
Expand Down Expand Up @@ -130,15 +127,21 @@ void MessageFactory::Types(std::vector<std::string> &_types)
{
_types.clear();

// Add the types loaded from descriptor files
std::vector<std::string> dynTypes;
this->dynamicFactory->Types(dynTypes);

// Use set to remove duplicates
std::unordered_set<std::string> typesSet(dynTypes.begin(), dynTypes.end());

// Return the list of all known message types.
std::map<std::string, FactoryFn>::const_iterator iter;
for (iter = msgMap.begin(); iter != msgMap.end(); ++iter)
{
_types.push_back(iter->first);
typesSet.insert(iter->first);
}

// Add the types loaded from descriptor files
this->dynamicFactory->Types(_types);
std::copy(typesSet.begin(), typesSet.end(), std::back_inserter(_types));
}

/////////////////////////////////////////////////
Expand Down

0 comments on commit ea75328

Please sign in to comment.