]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use map::find rather than insert to avoid creating temporary 13884/head
authorMartin Kronbichler <martin.kronbichler@uni-a.de>
Wed, 1 Jun 2022 13:47:19 +0000 (15:47 +0200)
committerMartin Kronbichler <martin.kronbichler@uni-a.de>
Wed, 1 Jun 2022 13:47:19 +0000 (15:47 +0200)
include/deal.II/matrix_free/dof_info.templates.h
include/deal.II/matrix_free/mapping_info.templates.h

index 3275827d590a0384cef91ff88187474babbed1bb..af5cc63571dcc34aaa64406d6fb6bd70a6dcfabf 100644 (file)
@@ -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.
index aa4b99917df4f05e06ff03913023add596b08e24..5aa4fb340922171f829a1ebe9d65ce99fe1efd20 100644 (file)
@@ -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;

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.