]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Avoid repeated re-allocation of memory.
authorWolfgang Bangerth <bangerth@colostate.edu>
Thu, 13 Jul 2023 23:06:28 +0000 (17:06 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Fri, 14 Jul 2023 01:43:40 +0000 (19:43 -0600)
While there, also keep track of information as we build it.

include/deal.II/lac/affine_constraints.templates.h

index 1302a89413d47851427856356a278a937ec125e2..189bc8d543cf3eb6d5d50d96c7993bc0f4ed4db6 100644 (file)
@@ -712,8 +712,9 @@ AffineConstraints<number>::close()
 #ifdef DEBUG
   size_type iteration = 0;
 #endif
-  bool              chained_constraint_replaced = false;
-  std::vector<bool> line_finalized(lines.size(), false);
+  bool                                chained_constraint_replaced = false;
+  std::vector<bool>                   line_finalized(lines.size(), false);
+  std::vector<const ConstraintLine *> sub_constraints;
   do
     {
       chained_constraint_replaced = false;
@@ -738,8 +739,8 @@ AffineConstraints<number>::close()
             // constrained, then store the address of the line it corresponds to
             // for further processing; this avoids having to look it up again,
             // which requires an IndexSet lookup. If not, store a nullptr.
-            std::vector<const ConstraintLine *> sub_constraints(
-              line.entries.size(), nullptr);
+            sub_constraints.resize(line.entries.size());
+            bool has_sub_constraints = false;
             for (unsigned int entry = 0; entry < line.entries.size(); ++entry)
               if (((local_lines.size() == 0) ||
                    (local_lines.is_element(line.entries[entry].first))) &&
@@ -748,13 +749,14 @@ AffineConstraints<number>::close()
                   const size_type dof_index = line.entries[entry].first;
                   sub_constraints[entry] =
                     &lines[lines_cache[calculate_line_index(dof_index)]];
+                  has_sub_constraints = true;
                 }
+              else
+                sub_constraints[entry] = nullptr;
 
             // If none of the entries in the current line refer to DoFs that are
             // themselves constrained, then we can move on:
-            if (std::none_of(sub_constraints.begin(),
-                             sub_constraints.end(),
-                             [](const auto p) { return (p != nullptr); }))
+            if (has_sub_constraints == false)
               {
                 line_finalized[line_index] = true;
                 continue;

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.