From: Martin Kronbichler Date: Wed, 1 Jun 2022 13:47:19 +0000 (+0200) Subject: Use map::find rather than insert to avoid creating temporary X-Git-Tag: v9.4.0-rc1~95^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ffbf1305fef25fe60526d67c0db52c8999f2aafc;p=dealii.git Use map::find rather than insert to avoid creating temporary --- diff --git a/include/deal.II/matrix_free/dof_info.templates.h b/include/deal.II/matrix_free/dof_info.templates.h index 3275827d59..af5cc63571 100644 --- a/include/deal.II/matrix_free/dof_info.templates.h +++ b/include/deal.II/matrix_free/dof_info.templates.h @@ -74,7 +74,6 @@ namespace internal next_constraint.first[j] = constraint_entries[j].second; } } - next_constraint.second = constraints.size(); // check whether or not constraint is already in pool. the initial // implementation computed a hash value based on the truncated array (to @@ -83,13 +82,16 @@ namespace internal // equal. this was quite lengthy and now we use a std::map with a // user-defined comparator to compare floating point arrays to a // tolerance 1e-13. - const auto it = constraints.insert(next_constraint); - types::global_dof_index insert_position = numbers::invalid_dof_index; - if (it.second == false) - insert_position = it.first->second; + const auto position = constraints.find(next_constraint.first); + if (position != constraints.end()) + insert_position = position->second; else - insert_position = next_constraint.second; + { + next_constraint.second = constraints.size(); + constraints.insert(next_constraint); + insert_position = next_constraint.second; + } // we want to store the result as a short variable, so we have to make // sure that the result does not exceed the limits when casting. diff --git a/include/deal.II/matrix_free/mapping_info.templates.h b/include/deal.II/matrix_free/mapping_info.templates.h index aa4b99917d..5aa4fb3409 100644 --- a/include/deal.II/matrix_free/mapping_info.templates.h +++ b/include/deal.II/matrix_free/mapping_info.templates.h @@ -1054,17 +1054,17 @@ namespace internal for (unsigned int cell = 0; cell < jacobians_on_stencil.size(); ++cell) { // check in the map for the index of this cell - auto inserted = compressed_jacobians.insert( - std::make_pair(jacobians_on_stencil[cell], cell)); - bool add_this_cell = inserted.second; - if (inserted.second == false) + const auto position = + compressed_jacobians.find(jacobians_on_stencil[cell]); + bool add_this_cell = position == compressed_jacobians.end(); + if (!add_this_cell) { // check if the found duplicate really is a translation and // the similarity identified by the map is not by accident double max_distance = 0; const double *ptr_origin = plain_quadrature_points.data() + - inserted.first->second * dim * n_mapping_points; + position->second * dim * n_mapping_points; const double *ptr_mine = plain_quadrature_points.data() + cell * dim * n_mapping_points; for (unsigned int d = 0; d < dim; ++d) @@ -1084,16 +1084,20 @@ namespace internal if (max_distance > 1e-10 * jacobian_size) add_this_cell = true; } + else + compressed_jacobians.insert( + std::make_pair(jacobians_on_stencil[cell], cell)); + if (add_this_cell) cell_data_index[cell] = n_data_buckets++; else { - cell_data_index[cell] = cell_data_index[inserted.first->second]; + cell_data_index[cell] = cell_data_index[position->second]; // make sure that the cell type is the same as in the original - // field, despite possible small differences due to roundoff + // field, despite possibly small differences due to roundoff // and the tolerances we use preliminary_cell_type[cell] = - preliminary_cell_type[inserted.first->second]; + preliminary_cell_type[position->second]; } } return cell_data_index;