From 705a0c07ca9f3708028660c41de6eadfad16e9f5 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Thu, 20 Dec 2018 23:32:51 +0100 Subject: [PATCH] Use empty() instead of size() to check if a vector/map contains elements and fixed some incorrect logging (#245) * rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/TypeSupport_impl.hpp: * rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/topic_cache.hpp: * rmw_fastrtps_shared_cpp/src/rmw_node_info_and_types.cpp: * rmw_fastrtps_shared_cpp/src/rmw_node_names.cpp: * rmw_fastrtps_shared_cpp/src/rmw_service_names_and_types.cpp: * rmw_fastrtps_shared_cpp/src/rmw_topic_names_and_types.cpp: --- .../include/rmw_fastrtps_dynamic_cpp/TypeSupport_impl.hpp | 3 +-- .../include/rmw_fastrtps_shared_cpp/topic_cache.hpp | 6 +++--- rmw_fastrtps_shared_cpp/src/rmw_node_info_and_types.cpp | 2 +- rmw_fastrtps_shared_cpp/src/rmw_node_names.cpp | 4 ++-- rmw_fastrtps_shared_cpp/src/rmw_service_names_and_types.cpp | 2 +- rmw_fastrtps_shared_cpp/src/rmw_topic_names_and_types.cpp | 2 +- 6 files changed, 9 insertions(+), 10 deletions(-) diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/TypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/TypeSupport_impl.hpp index 8216f71f3..e27f1ae92 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/TypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/TypeSupport_impl.hpp @@ -414,8 +414,7 @@ size_t next_field_align( std::vector & data = *reinterpret_cast *>(field); current_alignment += eprosima::fastcdr::Cdr::alignment(current_alignment, padding); current_alignment += padding; - auto num_elems = data.size(); - if (num_elems > 0) { + if (!data.empty()) { current_alignment += eprosima::fastcdr::Cdr::alignment(current_alignment, item_size); current_alignment += item_size * data.size(); } diff --git a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/topic_cache.hpp b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/topic_cache.hpp index 31ddcebea..77ba29329 100644 --- a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/topic_cache.hpp +++ b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/topic_cache.hpp @@ -156,7 +156,7 @@ class TopicCache { auto & type_vec = topic_to_types_[topic_name]; type_vec.erase(std::find(type_vec.begin(), type_vec.end(), type_name)); - if (type_vec.size() == 0) { + if (type_vec.empty()) { topic_to_types_.erase(topic_name); } } @@ -168,10 +168,10 @@ class TopicCache { auto & type_vec = guid_topics_pair->second[topic_name]; type_vec.erase(std::find(type_vec.begin(), type_vec.end(), type_name)); - if (type_vec.size() == 0) { + if (type_vec.empty()) { participant_to_topics_[guid].erase(topic_name); } - if (participant_to_topics_[guid].size() == 0) { + if (participant_to_topics_[guid].empty()) { participant_to_topics_.erase(guid); } } else { diff --git a/rmw_fastrtps_shared_cpp/src/rmw_node_info_and_types.cpp b/rmw_fastrtps_shared_cpp/src/rmw_node_info_and_types.cpp index df07b4ed8..7897f777f 100644 --- a/rmw_fastrtps_shared_cpp/src/rmw_node_info_and_types.cpp +++ b/rmw_fastrtps_shared_cpp/src/rmw_node_info_and_types.cpp @@ -194,7 +194,7 @@ __copy_data_to_results( rmw_names_and_types_t * topic_names_and_types) { // Copy data to results handle - if (topics.size() > 0) { + if (!topics.empty()) { // Setup string array to store names rmw_ret_t rmw_ret = rmw_names_and_types_init(topic_names_and_types, topics.size(), allocator); if (rmw_ret != RMW_RET_OK) { diff --git a/rmw_fastrtps_shared_cpp/src/rmw_node_names.cpp b/rmw_fastrtps_shared_cpp/src/rmw_node_names.cpp index bd7817613..4644edaf7 100644 --- a/rmw_fastrtps_shared_cpp/src/rmw_node_names.cpp +++ b/rmw_fastrtps_shared_cpp/src/rmw_node_names.cpp @@ -96,7 +96,7 @@ __rmw_get_node_names( rcutils_ret = rcutils_string_array_fini(node_names); if (rcutils_ret != RCUTILS_RET_OK) { RCUTILS_LOG_ERROR_NAMED( - "rmw_connext_cpp", + "rmw_fastrtps_cpp", "failed to cleanup during error handling: %s", rcutils_get_error_string().str); rcutils_reset_error(); } @@ -105,7 +105,7 @@ __rmw_get_node_names( rcutils_ret = rcutils_string_array_fini(node_namespaces); if (rcutils_ret != RCUTILS_RET_OK) { RCUTILS_LOG_ERROR_NAMED( - "rmw_connext_cpp", + "rmw_fastrtps_cpp", "failed to cleanup during error handling: %s", rcutils_get_error_string().str); rcutils_reset_error(); } diff --git a/rmw_fastrtps_shared_cpp/src/rmw_service_names_and_types.cpp b/rmw_fastrtps_shared_cpp/src/rmw_service_names_and_types.cpp index 20dae9c92..6ec29f1bc 100644 --- a/rmw_fastrtps_shared_cpp/src/rmw_service_names_and_types.cpp +++ b/rmw_fastrtps_shared_cpp/src/rmw_service_names_and_types.cpp @@ -90,7 +90,7 @@ __rmw_get_service_names_and_types( map_process(slave_target->writer_topic_cache); // Fill out service_names_and_types - if (services.size()) { + if (!services.empty()) { // Setup string array to store names rmw_ret_t rmw_ret = rmw_names_and_types_init(service_names_and_types, services.size(), allocator); diff --git a/rmw_fastrtps_shared_cpp/src/rmw_topic_names_and_types.cpp b/rmw_fastrtps_shared_cpp/src/rmw_topic_names_and_types.cpp index 88c235253..168e78a0b 100644 --- a/rmw_fastrtps_shared_cpp/src/rmw_topic_names_and_types.cpp +++ b/rmw_fastrtps_shared_cpp/src/rmw_topic_names_and_types.cpp @@ -97,7 +97,7 @@ __rmw_get_topic_names_and_types( map_process(slave_target->writer_topic_cache); // Copy data to results handle - if (topics.size() > 0) { + if (!topics.empty()) { // Setup string array to store names rmw_ret_t rmw_ret = rmw_names_and_types_init(topic_names_and_types, topics.size(), allocator); if (rmw_ret != RMW_RET_OK) {