]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Small improvement for IndexSet::add_ranges_internal 14052/head
authorMartin Kronbichler <martin.kronbichler@uni-a.de>
Sun, 26 Jun 2022 06:38:34 +0000 (08:38 +0200)
committerMartin Kronbichler <martin.kronbichler@uni-a.de>
Sun, 26 Jun 2022 06:38:34 +0000 (08:38 +0200)
source/base/index_set.cc

index 7b5960fe3fe1b0f19cbe21e28cb798589d58405b..1a47ae2c019fa6f1c8b0a94d9a0852dcc1f33eac 100644 (file)
@@ -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)

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.