]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Improve access speed to some functions by not calculating the line index more than...
authorkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 22 Dec 2010 15:20:02 +0000 (15:20 +0000)
committerkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 22 Dec 2010 15:20:02 +0000 (15:20 +0000)
git-svn-id: https://svn.dealii.org/trunk@23063 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/lac/constraint_matrix.h

index 96b3296cbfc9bb430bb53bfd2a2785e0d927025b..859398db9692f83ea120f65d206c0c4d7de1b1f9 100644 (file)
@@ -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<std::pair<unsigned int,double> >*
 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);
 }

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.