Skip to content

Commit

Permalink
Use empty() instead of size() to check if a vector/map contains eleme…
Browse files Browse the repository at this point in the history
…nts 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:
  • Loading branch information
jwillemsen authored and sloretz committed Dec 20, 2018
1 parent 117eebe commit 705a0c0
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,7 @@ size_t next_field_align(
std::vector<T> & data = *reinterpret_cast<std::vector<T> *>(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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion rmw_fastrtps_shared_cpp/src/rmw_node_info_and_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions rmw_fastrtps_shared_cpp/src/rmw_node_names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion rmw_fastrtps_shared_cpp/src/rmw_topic_names_and_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 705a0c0

Please sign in to comment.