Optimize Ref<SparseMatrix> by removing useless default initialisation of SparseMapBase and SparseMatrix

This commit is contained in:
Gael Guennebaud 2015-10-06 11:57:03 +02:00
parent 9a070638de
commit 945b80c83e
2 changed files with 13 additions and 5 deletions

View File

@ -120,6 +120,9 @@ class SparseMapBase<Derived,ReadOnlyAccessors>
/** Empty destructor */ /** Empty destructor */
inline ~SparseMapBase() {} inline ~SparseMapBase() {}
protected:
inline SparseMapBase() {}
}; };
template<typename Derived> template<typename Derived>
@ -172,6 +175,9 @@ class SparseMapBase<Derived,WriteAccessors>
/** Empty destructor */ /** Empty destructor */
inline ~SparseMapBase() {} inline ~SparseMapBase() {}
protected:
inline SparseMapBase() {}
}; };
template<typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType> template<typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType>

View File

@ -182,8 +182,9 @@ class Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType
{ {
if((Options & int(StandardCompressedFormat)) && (!expr.isCompressed())) if((Options & int(StandardCompressedFormat)) && (!expr.isCompressed()))
{ {
m_object = expr; TPlainObjectType* obj = reinterpret_cast<TPlainObjectType*>(m_object_bytes);
Base::construct(m_object); ::new (obj) TPlainObjectType(expr);
Base::construct(*obj);
} }
else else
{ {
@ -194,12 +195,13 @@ class Ref<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType
template<typename Expression> template<typename Expression>
void construct(const Expression& expr, internal::false_type) void construct(const Expression& expr, internal::false_type)
{ {
m_object = expr; TPlainObjectType* obj = reinterpret_cast<TPlainObjectType*>(m_object_bytes);
Base::construct(m_object); ::new (obj) TPlainObjectType(expr);
Base::construct(*obj);
} }
protected: protected:
TPlainObjectType m_object; char m_object_bytes[sizeof(TPlainObjectType)];
}; };