diff --git a/include/llama/VirtualRecord.hpp b/include/llama/VirtualRecord.hpp index d52763f174..ff576ec42a 100644 --- a/include/llama/VirtualRecord.hpp +++ b/include/llama/VirtualRecord.hpp @@ -45,24 +45,36 @@ namespace llama const VirtualRecord& right) -> LeftRecord& { using RightRecord = VirtualRecord; - forEachLeaf( - [&](auto leftCoord) - { - using LeftInnerCoord = decltype(leftCoord); - forEachLeaf( - [&](auto rightCoord) - { - using RightInnerCoord = decltype(rightCoord); - if constexpr (hasSameTags< - typename LeftRecord::AccessibleRecordDim, - LeftInnerCoord, - typename RightRecord::AccessibleRecordDim, - RightInnerCoord>) + // if the record dimension left and right is the same, a single loop is enough and no tag check is needed. + // this safes a lot of compilation time. + if constexpr (std::is_same_v< + typename LeftRecord::AccessibleRecordDim, + typename RightRecord::AccessibleRecordDim>) + { + forEachLeaf([&](auto coord) + { Functor{}(left(coord), right(coord)); }); + } + else + { + forEachLeaf( + [&](auto leftCoord) + { + using LeftInnerCoord = decltype(leftCoord); + forEachLeaf( + [&](auto rightCoord) { - Functor{}(left(leftCoord), right(rightCoord)); - } - }); - }); + using RightInnerCoord = decltype(rightCoord); + if constexpr (hasSameTags< + typename LeftRecord::AccessibleRecordDim, + LeftInnerCoord, + typename RightRecord::AccessibleRecordDim, + RightInnerCoord>) + { + Functor{}(left(leftCoord), right(rightCoord)); + } + }); + }); + } return left; } @@ -86,24 +98,36 @@ namespace llama { using RightRecord = VirtualRecord; bool result = true; - forEachLeaf( - [&](auto leftCoord) - { - using LeftInnerCoord = decltype(leftCoord); - forEachLeaf( - [&](auto rightCoord) - { - using RightInnerCoord = decltype(rightCoord); - if constexpr (hasSameTags< - typename LeftRecord::AccessibleRecordDim, - LeftInnerCoord, - typename RightRecord::AccessibleRecordDim, - RightInnerCoord>) + // if the record dimension left and right is the same, a single loop is enough and no tag check is needed. + // this safes a lot of compilation time. + if constexpr (std::is_same_v< + typename LeftRecord::AccessibleRecordDim, + typename RightRecord::AccessibleRecordDim>) + { + forEachLeaf( + [&](auto coord) { result &= Functor{}(left(coord), right(coord)); }); + } + else + { + forEachLeaf( + [&](auto leftCoord) + { + using LeftInnerCoord = decltype(leftCoord); + forEachLeaf( + [&](auto rightCoord) { - result &= Functor{}(left(leftCoord), right(rightCoord)); - } - }); - }); + using RightInnerCoord = decltype(rightCoord); + if constexpr (hasSameTags< + typename LeftRecord::AccessibleRecordDim, + LeftInnerCoord, + typename RightRecord::AccessibleRecordDim, + RightInnerCoord>) + { + result &= Functor{}(left(leftCoord), right(rightCoord)); + } + }); + }); + } return result; }