From: Wolfgang Bangerth Date: Wed, 22 Apr 2015 19:01:01 +0000 (-0500) Subject: In DynamicSparsityPattern iterators, also store a pointer to the end of the line... X-Git-Tag: v8.3.0-rc1~219^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F861%2Fhead;p=dealii.git In DynamicSparsityPattern iterators, also store a pointer to the end of the line to avoid repeated IndexSet lookups for every call to operator++. --- diff --git a/include/deal.II/lac/dynamic_sparsity_pattern.h b/include/deal.II/lac/dynamic_sparsity_pattern.h index a7b76e846c..21400616d0 100644 --- a/include/deal.II/lac/dynamic_sparsity_pattern.h +++ b/include/deal.II/lac/dynamic_sparsity_pattern.h @@ -124,6 +124,15 @@ namespace DynamicSparsityPatternIterators */ std::vector::const_iterator current_entry; + /** + * A pointer to the end of the current row. We store this + * to make comparison against the end of line iterator + * cheaper as it otherwise needs to do the IndexSet translation + * from row index to the index within the 'lines' array + * of DynamicSparsityPattern. + */ + std::vector::const_iterator end_of_row; + /** * Move the accessor to the next nonzero entry in the matrix. */ @@ -658,7 +667,12 @@ namespace DynamicSparsityPatternIterators : sparsity_pattern->lines[sparsity_pattern->rowset.index_within_set(current_row)].entries.begin()) + - index_within_row) + index_within_row), + end_of_row((sparsity_pattern->rowset.size()==0) + ? + sparsity_pattern->lines[current_row].entries.end() + : + sparsity_pattern->lines[sparsity_pattern->rowset.index_within_set(current_row)].entries.end()) { Assert (current_row < sparsity_pattern->n_rows(), ExcIndexRange (row, 0, sparsity_pattern->n_rows())); @@ -690,7 +704,8 @@ namespace DynamicSparsityPatternIterators : sparsity_pattern(sparsity_pattern), current_row(numbers::invalid_unsigned_int), - current_entry() + current_entry(), + end_of_row() {} @@ -778,12 +793,7 @@ namespace DynamicSparsityPatternIterators // the sparsity pattern. consequently, rather than trying to // duplicate code here, just call the begin() function of the // sparsity pattern itself - if (current_entry == - ((sparsity_pattern->rowset.size()==0) - ? - sparsity_pattern->lines[current_row].entries.end() - : - sparsity_pattern->lines[sparsity_pattern->rowset.index_within_set(current_row)].entries.end())) + if (current_entry == end_of_row) { if (current_row+1 < sparsity_pattern->n_rows()) *this = *sparsity_pattern->begin(current_row+1);