From ed0d9b83e5f1c222ae46a7cc7f6bec0576d86043 Mon Sep 17 00:00:00 2001 From: Bruno Turcksin Date: Tue, 3 May 2016 13:45:14 -0400 Subject: [PATCH] Use constant variable for end value of for loop. --- include/deal.II/lac/la_vector.h | 5 +++-- include/deal.II/lac/la_vector.templates.h | 27 +++++++++++++++-------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/include/deal.II/lac/la_vector.h b/include/deal.II/lac/la_vector.h index e14c508fbe..c89eb06094 100644 --- a/include/deal.II/lac/la_vector.h +++ b/include/deal.II/lac/la_vector.h @@ -383,7 +383,8 @@ namespace LinearAlgebra void Vector::add(const Number a) { AssertIsFinite(a); - for (unsigned int i=0; isize(); ++i) + const size_type size = this->size(); + for (size_type i=0; ival[i] += a; } @@ -424,7 +425,7 @@ namespace LinearAlgebra inline void Vector::serialize(Archive &ar, const unsigned int) { - unsigned int current_size = this->size(); + size_type current_size = this->size(); ar &static_cast(*this); ar &this->stored_elements; // If necessary, resize the vector during a read operation diff --git a/include/deal.II/lac/la_vector.templates.h b/include/deal.II/lac/la_vector.templates.h index de99473af3..5743151a64 100644 --- a/include/deal.II/lac/la_vector.templates.h +++ b/include/deal.II/lac/la_vector.templates.h @@ -28,7 +28,8 @@ namespace LinearAlgebra Vector &Vector::operator*= (const Number factor) { AssertIsFinite(factor); - for (unsigned int i=0; isize(); ++i) + const size_type size = this->size(); + for (size_type i=0; ival[i] *= factor; return *this; @@ -58,7 +59,8 @@ namespace LinearAlgebra const Vector &down_V = dynamic_cast&>(V); Assert(down_V.size()==this->size(), ExcMessage("Cannot add two vectors with different numbers of elements")); - for (unsigned int i=0; isize(); ++i) + const size_type size = this->size(); + for (size_type i=0; ival[i] += down_V[i]; @@ -79,7 +81,8 @@ namespace LinearAlgebra const Vector &down_V = dynamic_cast&>(V); Assert(down_V.size()==this->size(), ExcMessage("Cannot subtract two vectors with different numbers of elements")); - for (unsigned int i=0; isize(); ++i) + const size_type size = this->size(); + for (size_type i=0; ival[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; isize(); ++i) + for (size_type i=0; ival[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; isize(); ++i) + const size_type size = this->size(); + for (size_type i=0; ival[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; isize(); ++i) + const size_type size = this->size(); + for (size_type i=0; i&>(scaling_factors); Assert(down_scaling_factors.size()==this->size(), ExcMessage("Cannot add two vectors with different numbers of elements")); - for (unsigned int i=0; isize(); ++i) + const size_type size = this->size(); + for (size_type i=0; ival[i] *= down_scaling_factors[i]; @@ -264,7 +271,8 @@ namespace LinearAlgebra { real_type scale = 0.; real_type sum = 1.; - for (unsigned int i=0; isize(); ++i) + const size_type size = this->size(); + for (size_type i=0; ival[i] != Number()) { @@ -290,7 +298,8 @@ namespace LinearAlgebra typename VectorSpaceVector::real_type Vector::linfty_norm() const { typename ReadWriteVector::real_type norm = 0.; - for (unsigned int i=0; isize(); ++i) + const size_type size = this->size(); + for (size_type i=0; ival[i]),norm); return norm; -- 2.39.5