Skip to content

Commit

Permalink
Remove redundant ostream manipulators (#444)
Browse files Browse the repository at this point in the history
* remove redundant ostream manipulators

The following manipulators are sticky, and do not have to be repeated
for every item:

- setiosflags, resetiosflags, setbase, setfill, setprecision
- [no]boolalpha, [no]showbase, [no]showpoint, [no]showpos, [no]skipws,
  [no]unitbuf, [no]uppercase
- dec, hex, oct
- fixed, scientific
- internal, left, right

The only not sticky or persistent manipulator is setw, because all
output operators provided by the C++ library reset the width by
calling width(0) when beeing done.

Therefore the following test code works without any problem:

    ostringstream sfill;
    ostringstream sopti;

    sfill << hex << setfill('0') << setw(2) << 12
	  << hex << setfill('0') << setw(2) << 34
	  << hex << setfill('0') << setw(2) << 56;

    sopti << hex << setfill('0')
	  << setw(2) << 12
	  << setw(2) << 34
	  << setw(2) << 56;

    assert(sfill.str() == sopti.str());

The code savings using gcc 7.5.0 are as follows:

unoptimized     416432     9344     416  426192   680d0 libvsomeip3-cfg.so.3.3.0
                 49431     2760       8   52199    cbe7 libvsomeip3-e2e.so.3.3.0
                355217    11984     696  367897   59d19 libvsomeip3-sd.so.3.3.0
               2359943    65976    4336 2430255  25152f libvsomeip3.so.3.3.0

                 19967     1392     648   22007    55f7 examples/notify-sample
                 18912     1792     648   21352    5368 examples/subscribe-sample
                 20113     1456     648   22217    56c9 examples/request-sample
                 15131     1360     648   17139    42f3 examples/response-sample

optimized       416260     9344     416  426020   68024 libvsomeip3-cfg.so.3.3.0
                 49431     2760       8   52199    cbe7 libvsomeip3-e2e.so.3.3.0
                353693    11984     696  366373   59725 libvsomeip3-sd.so.3.3.0
               2343495    65976    4336 2413807  24d4ef libvsomeip3.so.3.3.0

                 19967     1392     648   22007    55f7 examples/notify-sample
                 18255     1792     648   20695    50d7 examples/subscribe-sample
                 19143     1456     648   21247    52ff examples/request-sample
                 15003     1360     648   17011    4273 examples/response-sample

Signed-off-by: Roman Fietze <[email protected]>

* fix missing whitespace after output operator

Signed-off-by: Roman Fietze <[email protected]>

---------

Signed-off-by: Roman Fietze <[email protected]>
  • Loading branch information
fietzero authored May 25, 2023
1 parent b0dc412 commit 0ba13d3
Show file tree
Hide file tree
Showing 34 changed files with 819 additions and 717 deletions.
18 changes: 10 additions & 8 deletions examples/request-sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,14 @@ class client_sample {

void on_message(const std::shared_ptr< vsomeip::message > &_response) {
std::cout << "Received a response from Service ["
<< std::setw(4) << std::setfill('0') << std::hex << _response->get_service()
<< std::setfill('0') << std::hex
<< std::setw(4) << _response->get_service()
<< "."
<< std::setw(4) << std::setfill('0') << std::hex << _response->get_instance()
<< std::setw(4) << _response->get_instance()
<< "] to Client/Session ["
<< std::setw(4) << std::setfill('0') << std::hex << _response->get_client()
<< std::setw(4) << _response->get_client()
<< "/"
<< std::setw(4) << std::setfill('0') << std::hex << _response->get_session()
<< std::setw(4) << _response->get_session()
<< "]"
<< std::endl;
if (is_available_)
Expand All @@ -154,13 +155,14 @@ class client_sample {
if (is_available_) {
app_->send(request_);
std::cout << "Client/Session ["
<< std::setw(4) << std::setfill('0') << std::hex << request_->get_client()
<< std::setfill('0') << std::hex
<< std::setw(4) << request_->get_client()
<< "/"
<< std::setw(4) << std::setfill('0') << std::hex << request_->get_session()
<< std::setw(4) << request_->get_session()
<< "] sent a request to Service ["
<< std::setw(4) << std::setfill('0') << std::hex << request_->get_service()
<< std::setw(4) << request_->get_service()
<< "."
<< std::setw(4) << std::setfill('0') << std::hex << request_->get_instance()
<< std::setw(4) << request_->get_instance()
<< "]"
<< std::endl;
blocked_ = false;
Expand Down
10 changes: 5 additions & 5 deletions examples/response-sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ class service_sample {
}

void on_message(const std::shared_ptr<vsomeip::message> &_request) {
std::cout << "Received a message with Client/Session [" << std::setw(4)
<< std::setfill('0') << std::hex << _request->get_client() << "/"
<< std::setw(4) << std::setfill('0') << std::hex
<< _request->get_session() << "]"
<< std::endl;
std::cout << "Received a message with Client/Session ["
<< std::setfill('0') << std::hex
<< std::setw(4) << _request->get_client() << "/"
<< std::setw(4) << _request->get_session() << "]"
<< std::endl;

std::shared_ptr<vsomeip::message> its_response
= vsomeip::runtime::get()->create_response(_request);
Expand Down
22 changes: 9 additions & 13 deletions examples/subscribe-sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,19 @@ class client_sample {
void on_message(const std::shared_ptr<vsomeip::message> &_response) {
std::stringstream its_message;
its_message << "Received a notification for Event ["
<< std::setw(4) << std::setfill('0') << std::hex
<< _response->get_service() << "."
<< std::setw(4) << std::setfill('0') << std::hex
<< _response->get_instance() << "."
<< std::setw(4) << std::setfill('0') << std::hex
<< _response->get_method() << "] to Client/Session ["
<< std::setw(4) << std::setfill('0') << std::hex
<< _response->get_client() << "/"
<< std::setw(4) << std::setfill('0') << std::hex
<< _response->get_session()
<< std::setfill('0') << std::hex
<< std::setw(4) << _response->get_service() << "."
<< std::setw(4) << _response->get_instance() << "."
<< std::setw(4) << _response->get_method() << "] to Client/Session ["
<< std::setw(4) << _response->get_client() << "/"
<< std::setw(4) << _response->get_session()
<< "] = ";
std::shared_ptr<vsomeip::payload> its_payload =
_response->get_payload();
its_message << "(" << std::dec << its_payload->get_length() << ") ";
its_message << "(" << std::dec << its_payload->get_length() << ") "
<< std::hex << std::setw(2);
for (uint32_t i = 0; i < its_payload->get_length(); ++i)
its_message << std::hex << std::setw(2) << std::setfill('0')
<< (int) its_payload->get_data()[i] << " ";
its_message << std::setw(2) << (int) its_payload->get_data()[i] << " ";
std::cout << its_message.str() << std::endl;

if (_response->get_client() == 0) {
Expand Down
44 changes: 22 additions & 22 deletions implementation/configuration/src/configuration_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,9 @@ bool configuration_impl::remote_offer_info_add(service_t _service,
if (!updated) {
services_[_service][_instance] = its_service;
VSOMEIP_INFO << "Added new remote configuration for service ["
<< std::hex << std::setw(4) << std::setfill('0')
<< its_service->service_ << "."
<< std::hex << std::setw(4) << std::setfill('0')
<< its_service->instance_ << "]";
<< std::hex << std::setfill('0')
<< std::setw(4) << its_service->service_ << "."
<< std::setw(4) << its_service->instance_ << "]";
}
if (_magic_cookies_enabled) {
magic_cookies_[its_service->unicast_address_].insert(its_service->reliable_);
Expand Down Expand Up @@ -2568,10 +2567,9 @@ configuration_impl::load_partition(const boost::property_tree::ptree &_tree) {
for (const auto &m : p.second) {
partitions_[p.first][m] = its_partition_id;
its_log << "<"
<< std::setw(4) << std::setfill('0') << std::hex
<< p.first << "."
<< std::setw(4) << std::setfill('0') << std::hex
<< m
<< std::setfill('0') << std::hex
<< std::setw(4) << p.first << "."
<< std::setw(4) << m
<< ">";
}
}
Expand Down Expand Up @@ -3807,9 +3805,9 @@ configuration_impl::load_service_debounce(
auto find_instance = find_service->second.find(its_instance);
if (find_instance != find_service->second.end()) {
VSOMEIP_ERROR << "Multiple debounce configurations for service "
<< std::hex << std::setw(4) << std::setfill('0') << its_service
<< "."
<< std::hex << std::setw(4) << std::setfill('0') << its_instance;
<< std::hex << std::setfill('0')
<< std::setw(4) << its_service << "."
<< std::setw(4) << its_instance;
return;
}
}
Expand Down Expand Up @@ -4215,12 +4213,13 @@ void configuration_impl::load_someip_tp_for_service(
= std::make_pair(its_max_segment_length, its_separation_time);
} else {
VSOMEIP_WARNING << "SOME/IP-TP: Multiple client configurations for method ["
<< std::hex << std::setw(4) << std::setfill('0') << _service->service_ << "."
<< std::hex << std::setw(4) << std::setfill('0') << _service->instance_ << "."
<< std::hex << std::setw(4) << std::setfill('0') << its_method << "]:"
<< " using ("
<< std::dec << its_entry->second.first << ", "
<< std::dec << its_entry->second.second << ")";
<< std::hex << std::setfill('0')
<< std::setw(4) << _service->service_ << "."
<< std::setw(4) << _service->instance_ << "."
<< std::setw(4) << its_method << "]:"
<< " using (" << std::dec
<< its_entry->second.first << ", "
<< its_entry->second.second << ")";
}
} else {
const auto its_entry = _service->tp_service_config_.find(its_method);
Expand All @@ -4229,11 +4228,12 @@ void configuration_impl::load_someip_tp_for_service(
= std::make_pair(its_max_segment_length, its_separation_time);
} else {
VSOMEIP_WARNING << "SOME/IP-TP: Multiple service configurations for method ["
<< std::hex << std::setw(4) << std::setfill('0') << _service->service_ << "."
<< std::hex << std::setw(4) << std::setfill('0') << _service->instance_ << "."
<< std::hex << std::setw(4) << std::setfill('0') << its_method << "]:"
<< " using ("
<< std::dec << its_entry->second.first << ", "
<< std::hex << std::setfill('0')
<< std::setw(4) << _service->service_ << "."
<< std::setw(4) << _service->instance_ << "."
<< std::setw(4) << its_method << "]:"
<< " using (" << std::dec
<< its_entry->second.first << ", "
<< std::dec << its_entry->second.second << ")";
}
}
Expand Down
35 changes: 19 additions & 16 deletions implementation/endpoints/src/client_endpoint_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,11 +539,12 @@ void client_endpoint_impl<Protocol>::send_cbk(
<< _error.message() << " (" << std::dec
<< _error.value() << ") " << get_remote_information()
<< " " << std::dec << queue_.size()
<< " " << std::dec << queue_size_ << " ("
<< std::hex << std::setw(4) << std::setfill('0') << its_client <<"): ["
<< std::hex << std::setw(4) << std::setfill('0') << its_service << "."
<< std::hex << std::setw(4) << std::setfill('0') << its_method << "."
<< std::hex << std::setw(4) << std::setfill('0') << its_session << "]";
<< " " << queue_size_ << " ("
<< std::hex << std::setfill('0')
<< std::setw(4) << its_client << "): ["
<< std::setw(4) << its_service << "."
<< std::setw(4) << its_method << "."
<< std::setw(4) << its_session << "]";
}
}
if (!stopping) {
Expand Down Expand Up @@ -601,12 +602,13 @@ void client_endpoint_impl<Protocol>::send_cbk(
VSOMEIP_WARNING << "cei::send_cbk received error: " << _error.message()
<< " (" << std::dec << _error.value() << ") "
<< get_remote_information() << " "
<< " " << std::dec << queue_.size()
<< " " << std::dec << queue_size_ << " ("
<< std::hex << std::setw(4) << std::setfill('0') << its_client <<"): ["
<< std::hex << std::setw(4) << std::setfill('0') << its_service << "."
<< std::hex << std::setw(4) << std::setfill('0') << its_method << "."
<< std::hex << std::setw(4) << std::setfill('0') << its_session << "]";
<< " " << queue_.size()
<< " " << queue_size_ << " ("
<< std::hex << std::setfill('0')
<< std::setw(4) << its_client << "): ["
<< std::setw(4) << its_service << "."
<< std::setw(4) << its_method << "."
<< std::setw(4) << its_session << "]";
print_status();
}
}
Expand Down Expand Up @@ -761,12 +763,13 @@ bool client_endpoint_impl<Protocol>::check_queue_limit(const uint8_t *_data, std
VSOMEIP_ERROR << "cei::check_queue_limit: queue size limit (" << std::dec
<< endpoint_impl<Protocol>::queue_limit_
<< ") reached. Dropping message ("
<< std::hex << std::setw(4) << std::setfill('0') << its_client <<"): ["
<< std::hex << std::setw(4) << std::setfill('0') << its_service << "."
<< std::hex << std::setw(4) << std::setfill('0') << its_method << "."
<< std::hex << std::setw(4) << std::setfill('0') << its_session << "] "
<< std::hex << std::setfill('0')
<< std::setw(4) << its_client << "): ["
<< std::setw(4) << its_service << "."
<< std::setw(4) << its_method << "."
<< std::setw(4) << its_session << "] "
<< "queue_size: " << std::dec << queue_size_
<< " data size: " << std::dec << _size;
<< " data size: " << _size;
return false;
}
return true;
Expand Down
4 changes: 2 additions & 2 deletions implementation/endpoints/src/endpoint_manager_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ endpoint_manager_base::log_client_states() const {
});

size_t its_max(std::min(size_t(10), its_client_queue_sizes.size()));
its_log << std::setfill('0');
for (size_t i = 0; i < its_max; i++) {
its_log << std::hex << std::setw(4) << std::setfill('0')
<< its_client_queue_sizes[i].first << ":"
its_log << std::hex << std::setw(4) << its_client_queue_sizes[i].first << ":"
<< std::dec << its_client_queue_sizes[i].second;
if (i < its_max-1)
its_log << ", ";
Expand Down
16 changes: 9 additions & 7 deletions implementation/endpoints/src/endpoint_manager_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ void endpoint_manager_impl::is_remote_service_known(
*_reliable_known = true;
} else {
VSOMEIP_WARNING << "Reliable service endpoint has changed: ["
<< std::hex << std::setfill('0') << std::setw(4) << _service << "."
<< std::hex << std::setfill('0') << std::setw(4) << _instance << "."
<< std::hex << std::setfill('0')
<< std::setw(4) << _service << "."
<< std::setw(4) << _instance << "."
<< std::dec << static_cast<std::uint32_t>(_major) << "."
<< std::dec << _minor << "] old: "
<< _minor << "] old: "
<< its_definition->get_address().to_string() << ":"
<< its_definition->get_port() << " new: "
<< _reliable_address.to_string() << ":"
Expand All @@ -149,10 +150,11 @@ void endpoint_manager_impl::is_remote_service_known(
*_unreliable_known = true;
} else {
VSOMEIP_WARNING << "Unreliable service endpoint has changed: ["
<< std::hex << std::setfill('0') << std::setw(4) << _service << "."
<< std::hex << std::setfill('0') << std::setw(4) << _instance << "."
<< std::hex << std::setfill('0')
<< std::setw(4) << _service << "."
<< std::setw(4) << _instance << "."
<< std::dec << static_cast<std::uint32_t>(_major) << "."
<< std::dec << _minor << "] old: "
<< _minor << "] old: "
<< its_definition->get_address().to_string() << ":"
<< its_definition->get_port() << " new: "
<< _unreliable_address.to_string() << ":"
Expand Down Expand Up @@ -496,7 +498,7 @@ void endpoint_manager_impl::find_or_create_multicast_endpoint(
its_udp_server_endpoint->join_unlocked(_address.to_string());
}
} else {
VSOMEIP_ERROR <<"Could not find/create multicast endpoint!";
VSOMEIP_ERROR << "Could not find/create multicast endpoint!";
}
}

Expand Down
15 changes: 7 additions & 8 deletions implementation/endpoints/src/local_tcp_server_endpoint_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,11 +599,11 @@ void local_tcp_server_endpoint_impl::connection::receive_cbk(
protocol::COMMAND_HEADER_SIZE + protocol::TAG_SIZE - recv_buffer_size_);
} else {
std::stringstream local_msg;
local_msg << std::setfill('0') << std::hex;
for (std::size_t i = its_iteration_gap;
i < recv_buffer_size_ + its_iteration_gap &&
i - its_iteration_gap < 32; i++) {
local_msg << std::setw(2) << std::setfill('0')
<< std::hex << (int) recv_buffer_[i] << " ";
local_msg << std::setw(2) << (int) recv_buffer_[i] << " ";
}
VSOMEIP_ERROR << "lse::c<" << this
<< ">rcb: recv_buffer_size is: " << std::dec
Expand Down Expand Up @@ -761,19 +761,18 @@ std::string local_tcp_server_endpoint_impl::connection::get_path_remote() const
void local_tcp_server_endpoint_impl::connection::handle_recv_buffer_exception(
const std::exception &_e) {
std::stringstream its_message;
its_message <<"local_tcp_server_endpoint_impl::connection catched exception"
its_message << "local_tcp_server_endpoint_impl::connection catched exception"
<< _e.what() << " local: " << get_path_local() << " remote: "
<< get_path_remote() << " shutting down connection. Start of buffer: ";
<< get_path_remote() << " shutting down connection. Start of buffer: "
<< std::setfill('0') << std::hex;

for (std::size_t i = 0; i < recv_buffer_size_ && i < 16; i++) {
its_message << std::setw(2) << std::setfill('0') << std::hex
<< (int) (recv_buffer_[i]) << " ";
its_message << std::setw(2) << (int) (recv_buffer_[i]) << " ";
}

its_message << " Last 16 Bytes captured: ";
for (int i = 15; recv_buffer_size_ > 15u && i >= 0; i--) {
its_message << std::setw(2) << std::setfill('0') << std::hex
<< (int) (recv_buffer_[static_cast<size_t>(i)]) << " ";
its_message << std::setw(2) << (int) (recv_buffer_[static_cast<size_t>(i)]) << " ";
}
VSOMEIP_ERROR << its_message.str();
recv_buffer_.clear();
Expand Down
Loading

0 comments on commit 0ba13d3

Please sign in to comment.