diff --git a/src/internal/Object.h b/src/internal/Object.h index 435759413..90bafb816 100644 --- a/src/internal/Object.h +++ b/src/internal/Object.h @@ -28,26 +28,45 @@ #include "Util.h" +template class Loop +{ + enum { + col = (count-1)/rows, + row = (count-1)%rows, + next = count-1 + }; + public: + template static void copy(Derived1 &dst, const Derived2 &src) + { + Loop::copy(dst, src); + dst.write(row, col) = src.read(row, col); + } +}; +template class Loop<0, rows> +{ + public: + template static void copy(Derived1 &dst, const Derived2 &src) + { + EI_UNUSED(dst); + EI_UNUSED(src); + } +}; + + template class EiObject { static const int RowsAtCompileTime = Derived::RowsAtCompileTime, - ColsAtCompileTime = Derived::ColsAtCompileTime; + ColsAtCompileTime = Derived::ColsAtCompileTime, + CountAtCompileTime= RowsAtCompileTime*ColsAtCompileTime > 0 ? + RowsAtCompileTime*ColsAtCompileTime : 0; template void _copy_helper(const EiObject& other) { - if(RowsAtCompileTime == 3 && ColsAtCompileTime == 3) - { - write(0,0) = other.read(0,0); - write(1,0) = other.read(1,0); - write(2,0) = other.read(2,0); - write(0,1) = other.read(0,1); - write(1,1) = other.read(1,1); - write(2,1) = other.read(2,1); - write(0,2) = other.read(0,2); - write(1,2) = other.read(1,2); - write(2,2) = other.read(2,2); - } + if ((RowsAtCompileTime != EiDynamic) && + (ColsAtCompileTime != EiDynamic) && + (CountAtCompileTime <= 25)) + Loop::copy(*this, other); else for(int i = 0; i < rows(); i++) for(int j = 0; j < cols(); j++)