From: Denis Davydov Date: Tue, 12 Jun 2018 20:52:03 +0000 (+0200) Subject: use range-based loops X-Git-Tag: v9.1.0-rc1~1047^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=09205a36df7415a3a8a413e769e55444c618824d;p=dealii.git use range-based loops --- diff --git a/source/base/timer.cc b/source/base/timer.cc index 2aeb758427..4405aa5141 100644 --- a/source/base/timer.cc +++ b/source/base/timer.cc @@ -548,10 +548,8 @@ TimerOutput::print_summary() const // get the maximum width among all sections unsigned int max_width = 0; - for (std::map::const_iterator i = sections.begin(); - i != sections.end(); - ++i) - max_width = std::max(max_width, (unsigned int)i->first.length()); + for (const auto &i : sections) + max_width = std::max(max_width, (unsigned int)i.first.length()); // 32 is the default width until | character max_width = std::max(max_width + 1, (unsigned int)32); @@ -570,11 +568,8 @@ TimerOutput::print_summary() const // time. otherwise, we might have generated a lot of overhead in this // function. double check_time = 0.; - for (std::map::const_iterator i = - sections.begin(); - i != sections.end(); - ++i) - check_time += i->second.total_cpu_time; + for (const auto &i : sections) + check_time += i.second.total_cpu_time; const double time_gap = check_time - total_cpu_time; if (time_gap > 0.0) @@ -601,12 +596,9 @@ TimerOutput::print_summary() const out_stream << "+---------------------------------" << extra_dash << "+-----------+------------" << "+------------+"; - for (std::map::const_iterator i = - sections.begin(); - i != sections.end(); - ++i) + for (const auto &i : sections) { - std::string name_out = i->first; + std::string name_out = i.first; // resize the array so that it is always of the same size unsigned int pos_non_space = name_out.find_first_not_of(' '); @@ -616,10 +608,10 @@ TimerOutput::print_summary() const out_stream << "| " << name_out; out_stream << "| "; out_stream << std::setw(9); - out_stream << i->second.n_calls << " |"; + out_stream << i.second.n_calls << " |"; out_stream << std::setw(10); out_stream << std::setprecision(3); - out_stream << i->second.total_cpu_time << "s |"; + out_stream << i.second.total_cpu_time << "s |"; out_stream << std::setw(10); if (total_cpu_time != 0) { @@ -627,7 +619,7 @@ TimerOutput::print_summary() const // printing silly things such as "2.45e-6%". otherwise print // the actual percentage const double fraction = - i->second.total_cpu_time / total_cpu_time; + i.second.total_cpu_time / total_cpu_time; if (fraction > 0.001) { out_stream << std::setprecision(2); @@ -681,12 +673,9 @@ TimerOutput::print_summary() const out_stream << "+---------------------------------" << extra_dash << "+-----------+------------" << "+------------+"; - for (std::map::const_iterator i = - sections.begin(); - i != sections.end(); - ++i) + for (const auto &i : sections) { - std::string name_out = i->first; + std::string name_out = i.first; // resize the array so that it is always of the same size unsigned int pos_non_space = name_out.find_first_not_of(' '); @@ -696,10 +685,10 @@ TimerOutput::print_summary() const out_stream << "| " << name_out; out_stream << "| "; out_stream << std::setw(9); - out_stream << i->second.n_calls << " |"; + out_stream << i.second.n_calls << " |"; out_stream << std::setw(10); out_stream << std::setprecision(3); - out_stream << i->second.total_wall_time << "s |"; + out_stream << i.second.total_wall_time << "s |"; out_stream << std::setw(10); if (total_wall_time != 0) @@ -708,7 +697,7 @@ TimerOutput::print_summary() const // printing silly things such as "2.45e-6%". otherwise print // the actual percentage const double fraction = - i->second.total_wall_time / total_wall_time; + i.second.total_wall_time / total_wall_time; if (fraction > 0.001) { out_stream << std::setprecision(2); @@ -740,10 +729,8 @@ TimerOutput::print_summary() const // otherwise, we might have generated a lot of overhead in this function. double check_time = 0.; - for (std::map::const_iterator i = sections.begin(); - i != sections.end(); - ++i) - check_time += i->second.total_cpu_time; + for (const auto &i : sections) + check_time += i.second.total_cpu_time; const double time_gap = check_time - total_cpu_time; if (time_gap > 0.0) @@ -773,11 +760,9 @@ TimerOutput::print_summary() const << "------------+------------+" << "------------+------------+" << std::endl; - for (std::map::const_iterator i = sections.begin(); - i != sections.end(); - ++i) + for (const auto &i : sections) { - std::string name_out = i->first; + std::string name_out = i.first; // resize the array so that it is always of the same size unsigned int pos_non_space = name_out.find_first_not_of(' '); @@ -786,13 +771,13 @@ TimerOutput::print_summary() const out_stream << "| " << name_out << "| "; out_stream << std::setw(9); - out_stream << i->second.n_calls << " |"; + out_stream << i.second.n_calls << " |"; if (output_type != wall_times) { out_stream << std::setw(10); out_stream << std::setprecision(3); - out_stream << i->second.total_cpu_time << "s |"; + out_stream << i.second.total_cpu_time << "s |"; out_stream << std::setw(10); if (total_cpu_time != 0) { @@ -800,7 +785,7 @@ TimerOutput::print_summary() const // printing silly things such as "2.45e-6%". otherwise print // the actual percentage const double fraction = - i->second.total_cpu_time / total_cpu_time; + i.second.total_cpu_time / total_cpu_time; if (fraction > 0.001) { out_stream << std::setprecision(2); @@ -819,7 +804,7 @@ TimerOutput::print_summary() const { out_stream << std::setw(10); out_stream << std::setprecision(3); - out_stream << i->second.total_wall_time << "s |"; + out_stream << i.second.total_wall_time << "s |"; out_stream << std::setw(10); if (total_wall_time != 0) @@ -828,7 +813,7 @@ TimerOutput::print_summary() const // printing silly things such as "2.45e-6%". otherwise print // the actual percentage const double fraction = - i->second.total_wall_time / total_wall_time; + i.second.total_wall_time / total_wall_time; if (fraction > 0.001) { out_stream << std::setprecision(2);