From edc24a970f23ea155969dc80564c71e760b3a72b Mon Sep 17 00:00:00 2001 From: David Wells Date: Thu, 22 Sep 2016 09:51:08 -0400 Subject: [PATCH] Prefer std::vector to std::list. The top comment implies that a previous version of this algorithm saved iterators into the temporary collection of new ranges (and hence this required std::list); however, since the current version stores no such iterators (it just uses push_back) we can make things a bit faster by using std::vector instead of std::list. --- source/base/index_set.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/source/base/index_set.cc b/source/base/index_set.cc index bff0e5349f..6126766db5 100644 --- a/source/base/index_set.cc +++ b/source/base/index_set.cc @@ -16,7 +16,8 @@ #include #include #include -#include + +#include #ifdef DEAL_II_WITH_TRILINOS # ifdef DEAL_II_WITH_MPI @@ -274,10 +275,9 @@ IndexSet::subtract_set (const IndexSet &other) is_compressed = false; - // we save new ranges to be added to our IndexSet in an temporary list and - // add all of them in one go at the end. This is necessary because a growing - // ranges vector invalidates iterators. - std::list temp_list; + // we save new ranges to be added to our IndexSet in an temporary vector and + // add all of them in one go at the end. + std::vector new_ranges; std::vector::iterator own_it = ranges.begin(); std::vector::iterator other_it = other.ranges.begin(); @@ -303,7 +303,7 @@ IndexSet::subtract_set (const IndexSet &other) { Range r(own_it->begin, other_it->begin); r.nth_index_in_set = 0; //fix warning of unused variable - temp_list.push_back(r); + new_ranges.push_back(r); } // change own_it to the sub range behind other_it. Do not delete own_it // in any case. As removal would invalidate iterators, we just shrink @@ -331,9 +331,9 @@ IndexSet::subtract_set (const IndexSet &other) } // done, now add the temporary ranges - for (std::list::iterator it = temp_list.begin(); - it != temp_list.end(); - ++it) + const std::vector::iterator end = new_ranges.end(); + for (std::vector::iterator it = new_ranges.begin(); + it != end; ++it) add_range(it->begin, it->end); compress(); -- 2.39.5