From: kronbichler Date: Wed, 22 Dec 2010 15:20:02 +0000 (+0000) Subject: Improve access speed to some functions by not calculating the line index more than... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f27c95abe74a96c87edf730d53a6abb6a4b9fdb;p=dealii-svn.git Improve access speed to some functions by not calculating the line index more than once. git-svn-id: https://svn.dealii.org/trunk@23063 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/lac/constraint_matrix.h b/deal.II/include/deal.II/lac/constraint_matrix.h index 96b3296cbf..859398db96 100644 --- a/deal.II/include/deal.II/lac/constraint_matrix.h +++ b/deal.II/include/deal.II/lac/constraint_matrix.h @@ -1871,8 +1871,16 @@ inline bool ConstraintMatrix::is_inhomogeneously_constrained (const unsigned int index) const { - return (is_constrained(index) && - lines[lines_cache[calculate_line_index(index)]].inhomogeneity != 0); + // check whether the entry is + // constrained. could use is_constrained, but + // that means computing the line index twice + const unsigned int line_index = calculate_line_index(index); + if (line_index > lines_cache.size() || + lines_cache[line_index] == numbers::invalid_unsigned_int || + lines[lines_cache[line_index]].inhomogeneity == 0) + return false; + else + return true; } @@ -1881,10 +1889,15 @@ inline const std::vector >* ConstraintMatrix::get_constraint_entries (unsigned int line) const { - if (is_constrained(line)) - return &lines[lines_cache[calculate_line_index(line)]].entries; - else + // check whether the entry is + // constrained. could use is_constrained, but + // that means computing the line index twice + const unsigned int line_index = calculate_line_index(line); + if (line_index > lines_cache.size() || + lines_cache[line_index] == numbers::invalid_unsigned_int) return 0; + else + return &lines[lines_cache[line_index]].entries; } @@ -1893,10 +1906,15 @@ inline double ConstraintMatrix::get_inhomogeneity (unsigned int line) const { - if (is_constrained(line)) - return lines[lines_cache[calculate_line_index(line)]].inhomogeneity; - else + // check whether the entry is + // constrained. could use is_constrained, but + // that means computing the line index twice + const unsigned int line_index = calculate_line_index(line); + if (line_index > lines_cache.size() || + lines_cache[line_index] == numbers::invalid_unsigned_int) return 0; + else + return lines[lines_cache[line_index]].inhomogeneity; } @@ -1917,7 +1935,7 @@ ConstraintMatrix::calculate_line_index (const unsigned int line) const inline bool -ConstraintMatrix::can_store_line(unsigned int line_index) const +ConstraintMatrix::can_store_line (unsigned int line_index) const { return !local_lines.size() || local_lines.is_element(line_index); }