From: Wolfgang Bangerth Date: Thu, 13 Jul 2023 23:06:28 +0000 (-0600) Subject: Avoid repeated re-allocation of memory. X-Git-Tag: relicensing~672^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=624abbec4d9c0eeba7d2bd01dcc51e9188868a97;p=dealii.git Avoid repeated re-allocation of memory. While there, also keep track of information as we build it. --- diff --git a/include/deal.II/lac/affine_constraints.templates.h b/include/deal.II/lac/affine_constraints.templates.h index 1302a89413..189bc8d543 100644 --- a/include/deal.II/lac/affine_constraints.templates.h +++ b/include/deal.II/lac/affine_constraints.templates.h @@ -712,8 +712,9 @@ AffineConstraints::close() #ifdef DEBUG size_type iteration = 0; #endif - bool chained_constraint_replaced = false; - std::vector line_finalized(lines.size(), false); + bool chained_constraint_replaced = false; + std::vector line_finalized(lines.size(), false); + std::vector sub_constraints; do { chained_constraint_replaced = false; @@ -738,8 +739,8 @@ AffineConstraints::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 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::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;