From: Martin Kronbichler Date: Sun, 26 Jun 2022 06:38:34 +0000 (+0200) Subject: Small improvement for IndexSet::add_ranges_internal X-Git-Tag: v9.5.0-rc1~1149^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F14052%2Fhead;p=dealii.git Small improvement for IndexSet::add_ranges_internal --- diff --git a/source/base/index_set.cc b/source/base/index_set.cc index 7b5960fe3f..1a47ae2c01 100644 --- a/source/base/index_set.cc +++ b/source/base/index_set.cc @@ -415,7 +415,17 @@ IndexSet::add_ranges_internal( tmp_set.ranges.reserve(tmp_ranges.size()); for (const auto &i : tmp_ranges) tmp_set.add_range(i.first, i.second); - this->add_indices(tmp_set); + + // Case if we have zero or just one range: Add into the other set with + // its indices, as that is cheaper + if (this->ranges.size() <= 1) + { + if (this->ranges.size() == 1) + tmp_set.add_range(ranges[0].begin, ranges[0].end); + std::swap(*this, tmp_set); + } + else + this->add_indices(tmp_set); } else for (const auto &i : tmp_ranges)