From ea75328fd9d6469cbaa9df6f0fe0be44c9446143 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Fri, 11 Oct 2024 01:24:40 +0000 Subject: [PATCH 1/2] remove duplicate types Signed-off-by: Ian Chen --- core/src/MessageFactory.cc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/core/src/MessageFactory.cc b/core/src/MessageFactory.cc index 45743dc1..6432db2d 100644 --- a/core/src/MessageFactory.cc +++ b/core/src/MessageFactory.cc @@ -15,6 +15,8 @@ * */ +#include + #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable: 4146 4251) @@ -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; @@ -130,15 +127,21 @@ void MessageFactory::Types(std::vector &_types) { _types.clear(); + // Add the types loaded from descriptor files + std::vector dynTypes; + this->dynamicFactory->Types(dynTypes); + + // Use set to remove duplicates + std::unordered_set typesSet(dynTypes.begin(), dynTypes.end()); + // Return the list of all known message types. std::map::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)); } ///////////////////////////////////////////////// From f0c4fecdeda95631190f68fb3205656d8cc6cdb7 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Fri, 11 Oct 2024 17:19:30 +0000 Subject: [PATCH 2/2] revert change Signed-off-by: Ian Chen --- core/src/MessageFactory.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/src/MessageFactory.cc b/core/src/MessageFactory.cc index 6432db2d..3558ea74 100644 --- a/core/src/MessageFactory.cc +++ b/core/src/MessageFactory.cc @@ -62,6 +62,11 @@ MessageFactory::MessagePtr MessageFactory::New( { type = kGzMsgsPrefix + _msgType.substr(8); } + // Convert ".gz.msgs." prefix + else if (_msgType.find(".gz.msgs.") == 0) + { + type = kGzMsgsPrefix + _msgType.substr(9); + } // Convert ".gz_msgs." prefix else if (_msgType.find(".gz_msgs.") == 0) {