]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use constant variable for end value of for loop.
authorBruno Turcksin <bruno.turcksin@gmail.com>
Tue, 3 May 2016 17:45:14 +0000 (13:45 -0400)
committerBruno Turcksin <bruno.turcksin@gmail.com>
Mon, 9 May 2016 12:23:01 +0000 (08:23 -0400)
include/deal.II/lac/la_vector.h
include/deal.II/lac/la_vector.templates.h

index e14c508fbe0962358007bd5ce52ae5d8f26ddf99..c89eb060942c9b8d39edb930b7c9c8cd29f4624b 100644 (file)
@@ -383,7 +383,8 @@ namespace LinearAlgebra
   void Vector<Number>::add(const Number a)
   {
     AssertIsFinite(a);
-    for (unsigned int i=0; i<this->size(); ++i)
+    const size_type size = this->size();
+    for (size_type i=0; i<size; ++i)
       this->val[i] += a;
   }
 
@@ -424,7 +425,7 @@ namespace LinearAlgebra
   inline
   void Vector<Number>::serialize(Archive &ar, const unsigned int)
   {
-    unsigned int current_size = this->size();
+    size_type current_size = this->size();
     ar &static_cast<Subscriptor &>(*this);
     ar &this->stored_elements;
     // If necessary, resize the vector during a read operation
index de99473af32f3e5d88415988104573951f9ba91c..5743151a64fcb569a4006ccef2affaac1c0504a0 100644 (file)
@@ -28,7 +28,8 @@ namespace LinearAlgebra
   Vector<Number> &Vector<Number>::operator*= (const Number factor)
   {
     AssertIsFinite(factor);
-    for (unsigned int i=0; i<this->size(); ++i)
+    const size_type size = this->size();
+    for (size_type i=0; i<size; ++i)
       this->val[i] *= factor;
 
     return *this;
@@ -58,7 +59,8 @@ namespace LinearAlgebra
     const Vector<Number> &down_V = dynamic_cast<const Vector<Number>&>(V);
     Assert(down_V.size()==this->size(),
            ExcMessage("Cannot add two vectors with different numbers of elements"));
-    for (unsigned int i=0; i<this->size(); ++i)
+    const size_type size = this->size();
+    for (size_type i=0; i<size; ++i)
       {
         AssertIsFinite(down_V[i]);
         this->val[i] += down_V[i];
@@ -79,7 +81,8 @@ namespace LinearAlgebra
     const Vector<Number> &down_V = dynamic_cast<const Vector<Number>&>(V);
     Assert(down_V.size()==this->size(),
            ExcMessage("Cannot subtract two vectors with different numbers of elements"));
-    for (unsigned int i=0; i<this->size(); ++i)
+    const size_type size = this->size();
+    for (size_type i=0; i<size; ++i)
       {
         AssertIsFinite(down_V[i]);
         this->val[i] -= down_V[i];
@@ -102,8 +105,9 @@ namespace LinearAlgebra
     Assert(down_V.size()==this->size(),
            ExcMessage("Cannot compute the scalar product "
                       "of two vectors with different numbers of elements"));
+    const size_type size = this->size();
     Number value = 0.;
-    for (unsigned int i=0; i<this->size(); ++i)
+    for (size_type i=0; i<size; ++i)
       {
         AssertIsFinite(down_V[i]);
         value += this->val[i]*down_V[i];
@@ -136,7 +140,8 @@ namespace LinearAlgebra
     AssertIsFinite(a);
     Assert(down_V.size()==this->size(),
            ExcMessage("Cannot add two vectors with different numbers of elements"));
-    for (unsigned int i=0; i<this->size(); ++i)
+    const size_type size = this->size();
+    for (size_type i=0; i<size; ++i)
       {
         AssertIsFinite(down_V[i]);
         this->val[i] += a*down_V[i];
@@ -166,7 +171,8 @@ namespace LinearAlgebra
     AssertIsFinite(b);
     Assert(down_W.size()==this->size(),
            ExcMessage("Cannot add two vectors with different numbers of elements"));
-    for (unsigned int i=0; i<this->size(); ++i)
+    const size_type size = this->size();
+    for (size_type i=0; i<size; ++i)
       {
         AssertIsFinite(down_V[i]);
         AssertIsFinite(down_W[i]);
@@ -206,7 +212,8 @@ namespace LinearAlgebra
       dynamic_cast<const Vector<Number>&>(scaling_factors);
     Assert(down_scaling_factors.size()==this->size(),
            ExcMessage("Cannot add two vectors with different numbers of elements"));
-    for (unsigned int i=0; i<this->size(); ++i)
+    const size_type size = this->size();
+    for (size_type i=0; i<size; ++i)
       {
         AssertIsFinite(down_scaling_factors[i]);
         this->val[i] *= down_scaling_factors[i];
@@ -264,7 +271,8 @@ namespace LinearAlgebra
       {
         real_type scale = 0.;
         real_type sum = 1.;
-        for (unsigned int i=0; i<this->size(); ++i)
+        const size_type size = this->size();
+        for (size_type i=0; i<size; ++i)
           {
             if (this->val[i] != Number())
               {
@@ -290,7 +298,8 @@ namespace LinearAlgebra
   typename VectorSpaceVector<Number>::real_type Vector<Number>::linfty_norm() const
   {
     typename ReadWriteVector<Number>::real_type norm = 0.;
-    for (unsigned int i=0; i<this->size(); ++i)
+    const size_type size = this->size();
+    for (size_type i=0; i<size; ++i)
       norm = std::max(std::abs(this->val[i]),norm);
 
     return norm;

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.