sw/inc/doc.hxx                               |    5 ++---
 sw/source/core/crsr/crsrsh.cxx               |    2 +-
 sw/source/core/doc/DocumentFieldsManager.cxx |    2 +-
 sw/source/core/doc/tblcpy.cxx                |    2 +-
 sw/source/core/docnode/ndtbl.cxx             |   20 ++++++++------------
 sw/source/core/edit/edtab.cxx                |    2 +-
 sw/source/core/frmedt/fecopy.cxx             |    2 +-
 sw/source/core/undo/unsort.cxx               |    2 +-
 sw/source/uibase/dochdl/swdtflvr.cxx         |    8 ++++----
 9 files changed, 20 insertions(+), 25 deletions(-)

New commits:
commit 9130c1abc65aedd0358d9f9dd4b9108b7e68f70f
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Sun Aug 7 13:42:18 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Mon Aug 8 19:27:36 2022 +0200

    make SwDoc::IsInTable more efficient
    
    Just follow the pointers, instead of unnecesarily indexing through
    the SwNodes array.
    
    Change-Id: I7da103d1300e1cbb54a8ca2994170fb7b2d9779f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137938
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index d63a10a1ec2e..0606ac4c33d1 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -1174,9 +1174,8 @@ public:
                                 bool bNewModel = true );
 
     // If index is in a table, return TableNode, else 0.
-    SwTableNode* IsIdxInTable( const SwNodeIndex& rIdx );
-    const SwTableNode* IsIdxInTable( const SwNodeIndex& rIdx ) const;
-    SwTableNode* IsInTable( const SwNode& ) const;
+    static SwTableNode* IsIdxInTable( const SwNodeIndex& rIdx );
+    static SwTableNode* IsInTable( const SwNode& );
 
     // Create a balanced table out of the selected range.
     const SwTable* TextToTable( const SwInsertTableOptions& rInsTableOpts, // 
HeadlineNoBorder,
diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
index 977b94e686fb..745fb43f5239 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -1601,7 +1601,7 @@ void SwCursorShell::UpdateCursor( sal_uInt16 eFlags, bool 
bIdleEnd )
     // then the table mode is active (also if it is already active: 
m_pTableCursor)
     SwPaM* pTstCursor = getShellCursor( true );
     if( pTstCursor->HasMark() && !m_pBlockCursor &&
-        mxDoc->IsIdxInTable( pTstCursor->GetPoint()->nNode ) &&
+        SwDoc::IsIdxInTable( pTstCursor->GetPoint()->nNode ) &&
           ( m_pTableCursor ||
             pTstCursor->GetNode().StartOfSectionNode() !=
             pTstCursor->GetNode( false ).StartOfSectionNode() ) && 
!mbSelectAll)
diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx 
b/sw/source/core/doc/DocumentFieldsManager.cxx
index cccdb2978b00..a9b22abe92d6 100644
--- a/sw/source/core/doc/DocumentFieldsManager.cxx
+++ b/sw/source/core/doc/DocumentFieldsManager.cxx
@@ -528,7 +528,7 @@ bool DocumentFieldsManager::UpdateField(SwTextField * 
pDstTextField, SwField & r
         case SwFieldIds::Table:
             {
                 const SwTableNode* pTableNd =
-                    m_rDoc.IsIdxInTable(aTableNdIdx);
+                    SwDoc::IsIdxInTable(aTableNdIdx);
                 if( pTableNd )
                 {
                     SwTableFormulaUpdate aTableUpdate( &pTableNd->
diff --git a/sw/source/core/doc/tblcpy.cxx b/sw/source/core/doc/tblcpy.cxx
index 135d558bb702..c7dc08b99934 100644
--- a/sw/source/core/doc/tblcpy.cxx
+++ b/sw/source/core/doc/tblcpy.cxx
@@ -707,7 +707,7 @@ bool SwTable::InsTable( const SwTable& rCpyTable, const 
SwNodeIndex& rSttBox,
 
     SwDoc* pDoc = GetFrameFormat()->GetDoc();
 
-    SwTableNode* pTableNd = pDoc->IsIdxInTable( rSttBox );
+    SwTableNode* pTableNd = SwDoc::IsIdxInTable( rSttBox );
 
     // Find the Box, to which should be copied:
     SwTableBox* pMyBox = GetTableBox(
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index 01e2dc21d173..c962688f9dd5 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -217,21 +217,17 @@ static SwTableBoxFormat *lcl_CreateAFormatBoxFormat( 
SwDoc &rDoc, std::vector<Sw
 }
 
 SwTableNode* SwDoc::IsIdxInTable( const SwNodeIndex& rIdx ) { return 
IsInTable(rIdx.GetNode()); }
-const SwTableNode* SwDoc::IsIdxInTable( const SwNodeIndex& rIdx ) const { 
return IsInTable(rIdx.GetNode()); }
 
-SwTableNode* SwDoc::IsInTable(const SwNode& rIdx) const
+SwTableNode* SwDoc::IsInTable(const SwNode& rIdx)
 {
-    SwTableNode* pTableNd = nullptr;
-    SwNodeOffset nIndex = rIdx.GetIndex();
+    SwNode* pNd = const_cast<SwNode*>(&rIdx);
     do {
-        SwNode* pNd = GetNodes()[ nIndex ]->StartOfSectionNode();
-        pTableNd = pNd->GetTableNode();
-        if( nullptr != pTableNd )
-            break;
-
-        nIndex = pNd->GetIndex();
-    } while ( nIndex );
-    return pTableNd;
+        pNd = pNd->StartOfSectionNode();
+        SwTableNode* pTableNd = pNd->GetTableNode();
+        if( pTableNd )
+            return pTableNd;
+    } while ( pNd->GetIndex() );
+    return nullptr;
 }
 
 /**
diff --git a/sw/source/core/edit/edtab.cxx b/sw/source/core/edit/edtab.cxx
index 0fa31a2425a0..5cb985686d8f 100644
--- a/sw/source/core/edit/edtab.cxx
+++ b/sw/source/core/edit/edtab.cxx
@@ -151,7 +151,7 @@ bool SwEditShell::TableToText( sal_Unicode cCh )
     SwWait aWait( *GetDoc()->GetDocShell(), true );
     SwPaM* pCursor = GetCursor();
     const SwTableNode* pTableNd =
-            GetDoc()->IsIdxInTable( pCursor->GetPoint()->nNode );
+            SwDoc::IsIdxInTable( pCursor->GetPoint()->nNode );
     if (!pTableNd)
         return false;
 
diff --git a/sw/source/core/frmedt/fecopy.cxx b/sw/source/core/frmedt/fecopy.cxx
index 68726cf5e196..cce62bd53f9b 100644
--- a/sw/source/core/frmedt/fecopy.cxx
+++ b/sw/source/core/frmedt/fecopy.cxx
@@ -966,7 +966,7 @@ bool SwFEShell::Paste(SwDoc& rClpDoc, bool bNestedTable)
         for(SwPaM& rPaM : GetCursor()->GetRingContainer())
         {
 
-            SwTableNode *const 
pDestNd(GetDoc()->IsIdxInTable(rPaM.GetPoint()->nNode));
+            SwTableNode *const 
pDestNd(SwDoc::IsIdxInTable(rPaM.GetPoint()->nNode));
             if (pSrcNd && nullptr != pDestNd &&
                 // not a forced nested table insertion
                 !bNestedTable &&
diff --git a/sw/source/core/undo/unsort.cxx b/sw/source/core/undo/unsort.cxx
index 44468c16546d..9008860776a6 100644
--- a/sw/source/core/undo/unsort.cxx
+++ b/sw/source/core/undo/unsort.cxx
@@ -235,7 +235,7 @@ void SwUndoSort::RepeatImpl(::sw::RepeatContext & rContext)
         SwPaM *const pPam = & rContext.GetRepeatPaM();
         SwDoc& rDoc = pPam->GetDoc();
 
-        if( !rDoc.IsIdxInTable( pPam->Start()->nNode ) )
+        if( !SwDoc::IsIdxInTable( pPam->Start()->nNode ) )
             rDoc.SortText(*pPam, *m_pSortOptions);
     }
 }
diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx 
b/sw/source/uibase/dochdl/swdtflvr.cxx
index 08377b49ee22..f2ce80ca7b1b 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -1521,7 +1521,7 @@ bool SwTransferable::Paste(SwWrtShell& rSh, 
TransferableDataHelper& rData, RndSt
 
         // convert the worksheet to a temporary native table using HTML 
format, and copy that into the original native table
         if (!bSingleCellTable && rData.HasFormat( SotClipboardFormatId::HTML ) 
&&
-                        rSh.GetDoc()->IsInTable(rSh.GetCursor()->GetNode()) != 
nullptr && rSh.DoesUndo())
+                        SwDoc::IsInTable(rSh.GetCursor()->GetNode()) != 
nullptr && rSh.DoesUndo())
         {
             SfxDispatcher* pDispatch = 
rSh.GetView().GetViewFrame()->GetDispatcher();
             sal_uInt32 nLevel = 0;
@@ -1534,13 +1534,13 @@ bool SwTransferable::Paste(SwWrtShell& rSh, 
TransferableDataHelper& rData, RndSt
                 pDispatch->Execute(FN_INSERT_NNBSP, SfxCallMode::SYNCHRON);
                 pDispatch->Execute(FN_TABLE_DELETE_TABLE, 
SfxCallMode::SYNCHRON);
                 nLevel++;
-            } while (rSh.GetDoc()->IsInTable(rSh.GetCursor()->GetNode()) != 
nullptr);
+            } while (SwDoc::IsInTable(rSh.GetCursor()->GetNode()) != nullptr);
             if ( SwTransferable::PasteData( rData, rSh, 
EXCHG_OUT_ACTION_INSERT_STRING, nActionFlags, SotClipboardFormatId::HTML,
                                         nDestination, false, false, nullptr, 
0, false, nAnchorType, bIgnoreComments, &aPasteContext, ePasteTable) )
             {
                 bool bFoundTemporaryTable = false;
                 pDispatch->Execute(FN_LINE_UP, SfxCallMode::SYNCHRON);
-                if (rSh.GetDoc()->IsInTable(rSh.GetCursor()->GetNode()) != 
nullptr)
+                if (SwDoc::IsInTable(rSh.GetCursor()->GetNode()) != nullptr)
                 {
                     bFoundTemporaryTable = true;
                     pDispatch->Execute(FN_TABLE_SELECT_ALL, 
SfxCallMode::SYNCHRON);
@@ -1570,7 +1570,7 @@ bool SwTransferable::Paste(SwWrtShell& rSh, 
TransferableDataHelper& rData, RndSt
     // insert clipboard content as new table rows/columns before the actual 
row/column instead of overwriting it
     else if ( (rSh.GetTableInsertMode() != SwTable::SEARCH_NONE || ePasteTable 
== PasteTableType::PASTE_ROW || ePasteTable == PasteTableType::PASTE_COLUMN) &&
         rData.HasFormat( SotClipboardFormatId::HTML ) &&
-        rSh.GetDoc()->IsInTable(rSh.GetCursor()->GetNode()) != nullptr )
+        SwDoc::IsInTable(rSh.GetCursor()->GetNode()) != nullptr )
     {
         OUString aExpand;
         sal_Int32 nIdx;

Reply via email to