Skip to content

Commit

Permalink
Use count to check if node exists
Browse files Browse the repository at this point in the history
Signed-off-by: Yadunund <[email protected]>
  • Loading branch information
Yadunund committed Sep 6, 2024
1 parent bda3ed6 commit 9d3274d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,7 @@ bool rmw_context_impl_s::create_node_data(
const std::string & node_name)
{
std::lock_guard<std::recursive_mutex> lock(data_->mutex_);
auto node_insertion = data_->nodes_.insert(std::make_pair(node, nullptr));
if (!node_insertion.second) {
if (data_->nodes_.count(node) > 0) {
// Node already exists.
return false;
}
Expand All @@ -478,7 +477,10 @@ bool rmw_context_impl_s::create_node_data(
return false;
}

node_insertion.first->second = std::move(node_data);
auto node_insertion = data_->nodes_.insert(std::make_pair(node, std::move(node_data)));
if (!node_insertion.second) {
return false;
}

return true;
}
Expand Down

0 comments on commit 9d3274d

Please sign in to comment.