sw/inc/ndarr.hxx                 |    4 +--
 sw/source/core/docnode/nodes.cxx |   46 +++++++++++++++------------------------
 2 files changed, 20 insertions(+), 30 deletions(-)

New commits:
commit e0f13ce0f9e2dac836c42141bb848d2bf4fbda75
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Tue Dec 21 13:52:56 2021 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Wed Dec 22 12:59:45 2021 +0100

    sw: simplify SwNodes::FindPrvNxtFrameNode(), pEnd is always passed
    
    Change-Id: I6bd606e8c70704cb716b1eb474934dedb54d81da
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127270
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/inc/ndarr.hxx b/sw/inc/ndarr.hxx
index 5393af72e776..28c96cc8a249 100644
--- a/sw/inc/ndarr.hxx
+++ b/sw/inc/ndarr.hxx
@@ -301,8 +301,8 @@ public:
     const   SwDoc& GetDoc() const   { return m_rMyDoc; }
 
     /** Search previous / next content node or table node with frames.
-     If no end is given begin with the FrameIndex, else start search
-     with that before rFrameIdx and pEnd at the back.
+     Search is started backward with the one before rFrameIdx and
+     forward after pEnd.
      If no valid node is found, return 0. rFrameIdx points to the node with 
frames. **/
     SwNode* FindPrvNxtFrameNode( SwNodeIndex& rFrameIdx,
                                 const SwNode* pEnd ) const;
diff --git a/sw/source/core/docnode/nodes.cxx b/sw/source/core/docnode/nodes.cxx
index 1b16c73b46eb..9ee61dd93d50 100644
--- a/sw/source/core/docnode/nodes.cxx
+++ b/sw/source/core/docnode/nodes.cxx
@@ -2027,8 +2027,7 @@ SwContentNode* SwNodes::GoPrevSection( SwNodeIndex * pIdx,
 /** find the next/previous ContentNode or table node that should have layout
  * frames that are siblings to the ones of the node at rFrameIdx.
  *
- * If no pEnd is given, search is started with FrameIndex; otherwise
- * search is started backward with the one before rFrameIdx and
+ * Search is started backward with the one before rFrameIdx and
  * forward after pEnd.
  *
  * @param rFrameIdx in: node with frames to search in; out: found node
@@ -2038,6 +2037,8 @@ SwContentNode* SwNodes::GoPrevSection( SwNodeIndex * pIdx,
 SwNode* SwNodes::FindPrvNxtFrameNode( SwNodeIndex& rFrameIdx,
                                     const SwNode* pEnd ) const
 {
+    assert(pEnd != nullptr); // every caller currently
+
     SwNode* pFrameNd = nullptr;
 
     // no layout -> skip
@@ -2057,12 +2058,8 @@ SwNode* SwNodes::FindPrvNxtFrameNode( SwNodeIndex& 
rFrameIdx,
                     ? pSttNd->StartOfSectionNode()->FindTableNode()
                     : pSttNd->FindTableNode();
             SwNodeIndex aIdx( rFrameIdx );
-            SwNode* pNd;
-            if( pEnd )
-            {
-                --aIdx;
-            }
-            pNd = &aIdx.GetNode();
+            --aIdx;
+            SwNode *const pNd = &aIdx.GetNode();
 
             if( ( pFrameNd = pNd )->IsContentNode() )
                 rFrameIdx = aIdx;
@@ -2083,13 +2080,10 @@ SwNode* SwNodes::FindPrvNxtFrameNode( SwNodeIndex& 
rFrameIdx,
             }
             else
             {
-                if( pEnd )
-                    aIdx = pEnd->GetIndex() + 1;
-                else
-                    aIdx = rFrameIdx;
+                aIdx = pEnd->GetIndex() + 1;
 
                 // NEVER leave the section when doing this!
-                if( ( pEnd && ( pFrameNd = &aIdx.GetNode())->IsContentNode() ) 
||
+                if( ( ( pFrameNd = &aIdx.GetNode())->IsContentNode() ) ||
                     ( nullptr != ( pFrameNd = GoNextSection( &aIdx, true, 
false )) &&
                     ::CheckNodesRange( aIdx, rFrameIdx, true ) &&
                     ( pFrameNd->FindTableNode() == pTableNd &&
@@ -2122,10 +2116,7 @@ SwNode* SwNodes::FindPrvNxtFrameNode( SwNodeIndex& 
rFrameIdx,
                 }
                 else
                 {
-                    if( pEnd )
-                        aIdx = pEnd->GetIndex() + 1;
-                    else
-                        aIdx = rFrameIdx.GetIndex() + 1;
+                    aIdx = pEnd->GetIndex() + 1;
 
                     if( (pFrameNd = &aIdx.GetNode())->IsTableNode() )
                         rFrameIdx = aIdx;
commit 25aa814aa466cb0a59e34dfef33c50065c445f60
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Tue Dec 21 13:47:32 2021 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Wed Dec 22 12:59:31 2021 +0100

    sw: simplify SwNodes::FindPrvNxtFrameNode(), improve comments
    
    Change-Id: I2f715ffe49d1c3ef373ffeb2a3cc335d511e0c13
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127269
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/source/core/docnode/nodes.cxx b/sw/source/core/docnode/nodes.cxx
index aa9dd63f4bfd..1b16c73b46eb 100644
--- a/sw/source/core/docnode/nodes.cxx
+++ b/sw/source/core/docnode/nodes.cxx
@@ -2023,16 +2023,17 @@ SwContentNode* SwNodes::GoPrevSection( SwNodeIndex * 
pIdx,
     return nullptr;
 }
 
-//TODO: improve documentation
 //TODO: The inventor of the "single responsibility principle" will be crying 
if you ever show this code to him!
-/** find the next/previous ContentNode or a table node with frames
+/** find the next/previous ContentNode or table node that should have layout
+ * frames that are siblings to the ones of the node at rFrameIdx.
  *
  * If no pEnd is given, search is started with FrameIndex; otherwise
- * search is started with the one before rFrameIdx and after pEnd.
+ * search is started backward with the one before rFrameIdx and
+ * forward after pEnd.
  *
- * @param rFrameIdx node with frames to search in
- * @param pEnd ???
- * @return result node; 0 (!!!) if not found
+ * @param rFrameIdx in: node with frames to search in; out: found node
+ * @param pEnd last node after rFrameIdx that should be excluded from search
+ * @return result node; 0 if not found
  */
 SwNode* SwNodes::FindPrvNxtFrameNode( SwNodeIndex& rFrameIdx,
                                     const SwNode* pEnd ) const
@@ -2042,17 +2043,17 @@ SwNode* SwNodes::FindPrvNxtFrameNode( SwNodeIndex& 
rFrameIdx,
     // no layout -> skip
     if( GetDoc().getIDocumentLayoutAccess().GetCurrentViewShell() )
     {
-        SwNode* pSttNd = &rFrameIdx.GetNode();
+        SwNode *const pSttNd = &rFrameIdx.GetNode();
 
-        // move of a hidden section?
-        SwSectionNode* pSectNd = pSttNd->IsSectionNode()
+        // inside a hidden section?
+        SwSectionNode *const pSectNd = pSttNd->IsSectionNode()
                     ? pSttNd->StartOfSectionNode()->FindSectionNode()
                     : pSttNd->FindSectionNode();
         if( !( pSectNd && pSectNd->GetSection().CalcHiddenFlag() ) )
         {
             // in a table in table situation we have to assure that we don't 
leave the
             // outer table cell when the inner table is looking for a PrvNxt...
-            SwTableNode* pTableNd = pSttNd->IsTableNode()
+            SwTableNode *const pTableNd = pSttNd->IsTableNode()
                     ? pSttNd->StartOfSectionNode()->FindTableNode()
                     : pSttNd->FindTableNode();
             SwNodeIndex aIdx( rFrameIdx );
@@ -2060,10 +2061,8 @@ SwNode* SwNodes::FindPrvNxtFrameNode( SwNodeIndex& 
rFrameIdx,
             if( pEnd )
             {
                 --aIdx;
-                pNd = &aIdx.GetNode();
             }
-            else
-                pNd = pSttNd;
+            pNd = &aIdx.GetNode();
 
             if( ( pFrameNd = pNd )->IsContentNode() )
                 rFrameIdx = aIdx;

Reply via email to