flag move constructor and swap function as noexcept for improved performance

This commit is contained in:
Axel Kohlmeyer
2025-06-24 06:12:40 -04:00
parent e8780449d8
commit d0c460e7f7
3 changed files with 16 additions and 16 deletions

View File

@ -215,8 +215,8 @@ namespace MathEigen {
public: public:
// C++ boilerplate: copy and move constructor, swap, and assignment operator // C++ boilerplate: copy and move constructor, swap, and assignment operator
Jacobi(const Jacobi<Scalar, Vector, Matrix, ConstMatrix>& source); Jacobi(const Jacobi<Scalar, Vector, Matrix, ConstMatrix>& source);
Jacobi(Jacobi<Scalar, Vector, Matrix, ConstMatrix>&& other); Jacobi(Jacobi<Scalar, Vector, Matrix, ConstMatrix>&& other) noexcept;
void swap(Jacobi<Scalar, Vector, Matrix, ConstMatrix> &other); void swap(Jacobi<Scalar, Vector, Matrix, ConstMatrix> &other) noexcept;
Jacobi<Scalar, Vector, Matrix, ConstMatrix>& operator = (Jacobi<Scalar, Vector, Matrix, ConstMatrix> source); Jacobi<Scalar, Vector, Matrix, ConstMatrix>& operator = (Jacobi<Scalar, Vector, Matrix, ConstMatrix> source);
}; // class Jacobi }; // class Jacobi
@ -878,7 +878,7 @@ Jacobi(const Jacobi<Scalar, Vector, Matrix, ConstMatrix>& source)
template<typename Scalar,typename Vector,typename Matrix,typename ConstMatrix> template<typename Scalar,typename Vector,typename Matrix,typename ConstMatrix>
void Jacobi<Scalar, Vector, Matrix, ConstMatrix>:: void Jacobi<Scalar, Vector, Matrix, ConstMatrix>::
swap(Jacobi<Scalar, Vector, Matrix, ConstMatrix> &other) { swap(Jacobi<Scalar, Vector, Matrix, ConstMatrix> &other) noexcept {
std::swap(n, other.n); std::swap(n, other.n);
std::swap(is_preallocated, other.is_preallocated); std::swap(is_preallocated, other.is_preallocated);
std::swap(max_idx_row, other.max_idx_row); std::swap(max_idx_row, other.max_idx_row);
@ -888,7 +888,7 @@ swap(Jacobi<Scalar, Vector, Matrix, ConstMatrix> &other) {
// Move constructor (C++11) // Move constructor (C++11)
template<typename Scalar,typename Vector,typename Matrix,typename ConstMatrix> template<typename Scalar,typename Vector,typename Matrix,typename ConstMatrix>
Jacobi<Scalar, Vector, Matrix, ConstMatrix>:: Jacobi<Scalar, Vector, Matrix, ConstMatrix>::
Jacobi(Jacobi<Scalar, Vector, Matrix, ConstMatrix>&& other) { Jacobi(Jacobi<Scalar, Vector, Matrix, ConstMatrix>&& other) noexcept {
Init(); Init();
this->swap(other); this->swap(other);
} }

View File

@ -65,7 +65,7 @@ Tokenizer::Tokenizer(const Tokenizer &rhs) :
reset(); reset();
} }
Tokenizer::Tokenizer(Tokenizer &&rhs) : Tokenizer::Tokenizer(Tokenizer &&rhs) noexcept :
text(std::move(rhs.text)), separators(std::move(rhs.separators)), ntokens(rhs.ntokens) text(std::move(rhs.text)), separators(std::move(rhs.separators)), ntokens(rhs.ntokens)
{ {
reset(); reset();
@ -78,14 +78,14 @@ Tokenizer &Tokenizer::operator=(const Tokenizer &other)
return *this; return *this;
} }
Tokenizer &Tokenizer::operator=(Tokenizer &&other) Tokenizer &Tokenizer::operator=(Tokenizer &&other) noexcept
{ {
Tokenizer tmp(std::move(other)); Tokenizer tmp(std::move(other));
swap(tmp); swap(tmp);
return *this; return *this;
} }
void Tokenizer::swap(Tokenizer &other) void Tokenizer::swap(Tokenizer &other) noexcept
{ {
std::swap(text, other.text); std::swap(text, other.text);
std::swap(separators, other.separators); std::swap(separators, other.separators);
@ -221,7 +221,7 @@ ValueTokenizer::ValueTokenizer(const std::string &str, const std::string &separa
{ {
} }
ValueTokenizer::ValueTokenizer(ValueTokenizer &&rhs) : tokens(std::move(rhs.tokens)) {} ValueTokenizer::ValueTokenizer(ValueTokenizer &&rhs) noexcept : tokens(std::move(rhs.tokens)) {}
ValueTokenizer &ValueTokenizer::operator=(const ValueTokenizer &other) ValueTokenizer &ValueTokenizer::operator=(const ValueTokenizer &other)
{ {
@ -230,14 +230,14 @@ ValueTokenizer &ValueTokenizer::operator=(const ValueTokenizer &other)
return *this; return *this;
} }
ValueTokenizer &ValueTokenizer::operator=(ValueTokenizer &&other) ValueTokenizer &ValueTokenizer::operator=(ValueTokenizer &&other) noexcept
{ {
ValueTokenizer tmp(std::move(other)); ValueTokenizer tmp(std::move(other));
swap(tmp); swap(tmp);
return *this; return *this;
} }
void ValueTokenizer::swap(ValueTokenizer &other) void ValueTokenizer::swap(ValueTokenizer &other) noexcept
{ {
std::swap(tokens, other.tokens); std::swap(tokens, other.tokens);
} }

View File

@ -36,11 +36,11 @@ class Tokenizer {
public: public:
Tokenizer(std::string str, std::string separators = TOKENIZER_DEFAULT_SEPARATORS); Tokenizer(std::string str, std::string separators = TOKENIZER_DEFAULT_SEPARATORS);
Tokenizer(Tokenizer &&); Tokenizer(Tokenizer &&) noexcept;
Tokenizer(const Tokenizer &); Tokenizer(const Tokenizer &);
Tokenizer &operator=(const Tokenizer &); Tokenizer &operator=(const Tokenizer &);
Tokenizer &operator=(Tokenizer &&); Tokenizer &operator=(Tokenizer &&) noexcept;
void swap(Tokenizer &); void swap(Tokenizer &) noexcept;
void reset(); void reset();
void skip(int n = 1); void skip(int n = 1);
@ -111,10 +111,10 @@ class ValueTokenizer {
ValueTokenizer(const std::string &str, ValueTokenizer(const std::string &str,
const std::string &separators = TOKENIZER_DEFAULT_SEPARATORS); const std::string &separators = TOKENIZER_DEFAULT_SEPARATORS);
ValueTokenizer(const ValueTokenizer &) = default; ValueTokenizer(const ValueTokenizer &) = default;
ValueTokenizer(ValueTokenizer &&); ValueTokenizer(ValueTokenizer &&) noexcept;
ValueTokenizer &operator=(const ValueTokenizer &); ValueTokenizer &operator=(const ValueTokenizer &);
ValueTokenizer &operator=(ValueTokenizer &&); ValueTokenizer &operator=(ValueTokenizer &&) noexcept;
void swap(ValueTokenizer &); void swap(ValueTokenizer &) noexcept;
std::string next_string(); std::string next_string();
tagint next_tagint(); tagint next_tagint();