From c11550c75e34f1f3ee16363a2e7bb482ee7b9652 Mon Sep 17 00:00:00 2001 From: bangerth Date: Mon, 12 Oct 2009 18:49:04 +0000 Subject: [PATCH] Optimize cases by asking for the size of a container first before creating begin/end iterators and seeing if this denotes an empty loop. git-svn-id: https://svn.dealii.org/trunk@19834 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/index_set.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/deal.II/base/include/base/index_set.h b/deal.II/base/include/base/index_set.h index 1bf8729d9b..acf130640c 100644 --- a/deal.II/base/include/base/index_set.h +++ b/deal.II/base/include/base/index_set.h @@ -267,17 +267,19 @@ IndexSet::is_element (const unsigned int index) const { // see if it's in the list of // individual indices - if (individual_indices.find (index) != individual_indices.end()) + if ((individual_indices.size() > 0) && + (individual_indices.find (index) != individual_indices.end())) return true; // if not, we need to walk the list // of contiguous ranges: - for (std::set::const_iterator - i = contiguous_ranges.begin(); - i != contiguous_ranges.end(); - ++i) - if ((index >= i->first) && (index < i->second)) - return true; + if (contiguous_ranges.size() > 0) + for (std::set::const_iterator + i = contiguous_ranges.begin(); + i != contiguous_ranges.end(); + ++i) + if ((index >= i->first) && (index < i->second)) + return true; // didn't find this index, so it's // not in the set -- 2.39.5