From: Peter Munch Date: Thu, 12 Sep 2024 20:16:37 +0000 (+0200) Subject: AffineConstraints: Improve loop X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=59761b5b440100de84a879bed52a053290558c98;p=dealii.git AffineConstraints: Improve loop --- diff --git a/include/deal.II/lac/affine_constraints.templates.h b/include/deal.II/lac/affine_constraints.templates.h index e75850c92d..07c6aacae8 100644 --- a/include/deal.II/lac/affine_constraints.templates.h +++ b/include/deal.II/lac/affine_constraints.templates.h @@ -482,18 +482,32 @@ namespace internal std::vector data; - for (const types::global_dof_index index : indices) + auto i = indices.begin(); + + auto j = std::lower_bound(locally_relevant_constraints.begin(), + locally_relevant_constraints.end(), + *i, + [&](const auto &a, const auto &b) { + return a.index < b; + }); + + for (; (i != indices.end()) && + (j != locally_relevant_constraints.end());) { - // note: at this stage locally_relevant_constraints still - // contains only locally owned constraints - const typename std::vector::iterator ptr = - std::find_if(locally_relevant_constraints.begin(), - locally_relevant_constraints.end(), - [index](const auto &a) { - return a.index == index; - }); - if (ptr != locally_relevant_constraints.end()) - data.push_back(*ptr); + if (*i == j->index) + { + data.push_back(*j); + ++i; + ++j; + } + else if (*i < j->index) + { + ++i; + } + else + { + ++j; + } } send_data[destination] = std::move(data);