From cf6d3162cce31f608a9e2a3d7a722334fd8f7695 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 17 May 2010 16:54:17 +0200 Subject: [PATCH] cache outer size in Block => x1.5 speed up for a.block() = b.block() --- Eigen/src/Core/Block.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h index 6f338d020..dd07142c6 100644 --- a/Eigen/src/Core/Block.h +++ b/Eigen/src/Core/Block.h @@ -253,6 +253,7 @@ class Block ei_assert( (i>=0) && ( ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && i { ei_assert(startRow >= 0 && BlockRows >= 1 && startRow + BlockRows <= xpr.rows() && startCol >= 0 && BlockCols >= 1 && startCol + BlockCols <= xpr.cols()); + init(); } /** Dynamic-size constructor @@ -276,6 +278,7 @@ class Block && (ColsAtCompileTime==Dynamic || ColsAtCompileTime==blockCols)); ei_assert(startRow >= 0 && blockRows >= 0 && startRow + blockRows <= xpr.rows() && startCol >= 0 && blockCols >= 0 && startCol + blockCols <= xpr.cols()); + init(); } /** \sa MapBase::innerStride() */ @@ -289,9 +292,7 @@ class Block /** \sa MapBase::outerStride() */ inline int outerStride() const { - return ei_traits::HasSameStorageOrderAsXprType - ? m_xpr.outerStride() - : m_xpr.innerStride(); + return m_outerStride; } #ifndef __SUNPRO_CC @@ -304,11 +305,21 @@ class Block /** \internal used by allowAligned() */ inline Block(const XprType& xpr, const Scalar* data, int blockRows, int blockCols) : Base(data, blockRows, blockCols), m_xpr(xpr) - {} + { + init(); + } #endif protected: + void init() + { + m_outerStride = ei_traits::HasSameStorageOrderAsXprType + ? m_xpr.outerStride() + : m_xpr.innerStride(); + } + const typename XprType::Nested m_xpr; + int m_outerStride; }; /** \returns a dynamic-size expression of a block in *this.