From 945b80c83e3bb7320667e8a9a45fc4912af85c79 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 6 Oct 2015 11:57:03 +0200 Subject: [PATCH] Optimize Ref by removing useless default initialisation of SparseMapBase and SparseMatrix --- Eigen/src/SparseCore/SparseMap.h | 6 ++++++ Eigen/src/SparseCore/SparseRef.h | 12 +++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Eigen/src/SparseCore/SparseMap.h b/Eigen/src/SparseCore/SparseMap.h index 2ef4181bc..058a6d62b 100644 --- a/Eigen/src/SparseCore/SparseMap.h +++ b/Eigen/src/SparseCore/SparseMap.h @@ -120,6 +120,9 @@ class SparseMapBase /** Empty destructor */ inline ~SparseMapBase() {} + + protected: + inline SparseMapBase() {} }; template @@ -172,6 +175,9 @@ class SparseMapBase /** Empty destructor */ inline ~SparseMapBase() {} + + protected: + inline SparseMapBase() {} }; template diff --git a/Eigen/src/SparseCore/SparseRef.h b/Eigen/src/SparseCore/SparseRef.h index 08268b9e1..fbd489a13 100644 --- a/Eigen/src/SparseCore/SparseRef.h +++ b/Eigen/src/SparseCore/SparseRef.h @@ -182,8 +182,9 @@ class Ref, Options, StrideType { if((Options & int(StandardCompressedFormat)) && (!expr.isCompressed())) { - m_object = expr; - Base::construct(m_object); + TPlainObjectType* obj = reinterpret_cast(m_object_bytes); + ::new (obj) TPlainObjectType(expr); + Base::construct(*obj); } else { @@ -194,12 +195,13 @@ class Ref, Options, StrideType template void construct(const Expression& expr, internal::false_type) { - m_object = expr; - Base::construct(m_object); + TPlainObjectType* obj = reinterpret_cast(m_object_bytes); + ::new (obj) TPlainObjectType(expr); + Base::construct(*obj); } protected: - TPlainObjectType m_object; + char m_object_bytes[sizeof(TPlainObjectType)]; };