From aca028085e64b33ccdde30e7a6c0d6bc03d05c16 Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Sun, 26 Jun 2022 08:38:34 +0200 Subject: [PATCH] Small improvement for IndexSet::add_ranges_internal --- source/base/index_set.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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) -- 2.39.5