sw/inc/htmltbl.hxx                                      |    2 
 sw/inc/node.hxx                                         |   21 +-
 sw/inc/pam.hxx                                          |    2 
 sw/source/core/SwNumberTree/SwNodeNum.cxx               |    2 
 sw/source/core/access/AccessibilityCheck.cxx            |   24 +-
 sw/source/core/access/accpara.cxx                       |   10 -
 sw/source/core/attr/cellatr.cxx                         |    2 
 sw/source/core/attr/swatrset.cxx                        |    2 
 sw/source/core/crsr/crsrsh.cxx                          |    4 
 sw/source/core/crsr/crstrvl.cxx                         |    4 
 sw/source/core/crsr/findtxt.cxx                         |    6 
 sw/source/core/crsr/pam.cxx                             |    8 
 sw/source/core/crsr/swcrsr.cxx                          |    2 
 sw/source/core/crsr/trvlfnfl.cxx                        |    2 
 sw/source/core/crsr/trvltbl.cxx                         |    8 
 sw/source/core/crsr/viscrs.cxx                          |    2 
 sw/source/core/doc/CntntIdxStore.cxx                    |    8 
 sw/source/core/doc/DocumentContentOperationsManager.cxx |  152 +++++++--------
 sw/source/core/doc/dbgoutsw.cxx                         |   37 +--
 sw/source/core/doc/docbm.cxx                            |   10 -
 sw/source/core/doc/doccomp.cxx                          |    8 
 sw/source/core/doc/doccorr.cxx                          |   16 -
 sw/source/core/doc/docedt.cxx                           |   28 +-
 sw/source/core/doc/docfld.cxx                           |    4 
 sw/source/core/doc/docfmt.cxx                           |    6 
 sw/source/core/doc/docnew.cxx                           |    6 
 sw/source/core/doc/doctxm.cxx                           |   64 +++---
 sw/source/core/doc/ftnidx.cxx                           |   32 +--
 sw/source/core/doc/htmltbl.cxx                          |    8 
 sw/source/core/doc/notxtfrm.cxx                         |    4 
 sw/source/core/doc/number.cxx                           |    4 
 sw/source/core/doc/rdfhelper.cxx                        |   16 -
 sw/source/core/doc/tblrwcl.cxx                          |    4 
 sw/source/core/docnode/ndcopy.cxx                       |    6 
 sw/source/core/docnode/ndnotxt.cxx                      |    2 
 sw/source/core/docnode/ndsect.cxx                       |    4 
 sw/source/core/docnode/ndtbl.cxx                        |   17 -
 sw/source/core/docnode/ndtbl1.cxx                       |   10 -
 sw/source/core/docnode/node.cxx                         |   86 ++++----
 sw/source/core/docnode/nodes.cxx                        |   36 +--
 sw/source/core/docnode/section.cxx                      |   18 -
 sw/source/core/docnode/swbaslnk.cxx                     |   20 +-
 sw/source/core/edit/acorrect.cxx                        |    2 
 sw/source/core/edit/edfcol.cxx                          |    8 
 sw/source/core/edit/edtab.cxx                           |    2 
 sw/source/core/fields/authfld.cxx                       |    2 
 sw/source/core/fields/cellfml.cxx                       |    2 
 sw/source/core/fields/chpfld.cxx                        |   10 -
 sw/source/core/fields/expfld.cxx                        |    2 
 sw/source/core/fields/reffld.cxx                        |    4 
 sw/source/core/frmedt/fefly1.cxx                        |    2 
 sw/source/core/frmedt/fetab.cxx                         |    2 
 sw/source/core/frmedt/tblsel.cxx                        |   24 +-
 sw/source/core/graphic/ndgrf.cxx                        |   12 -
 sw/source/core/layout/calcmove.cxx                      |    4 
 sw/source/core/layout/frmtool.cxx                       |   10 -
 sw/source/core/layout/ssfrm.cxx                         |    6 
 sw/source/core/layout/wsfrm.cxx                         |    4 
 sw/source/core/ole/ndole.cxx                            |   34 +--
 sw/source/core/text/EnhancedPDFExportHelper.cxx         |    4 
 sw/source/core/text/itratr.cxx                          |    4 
 sw/source/core/text/porlay.cxx                          |    2 
 sw/source/core/text/redlnitr.cxx                        |    8 
 sw/source/core/text/txtfld.cxx                          |    8 
 sw/source/core/text/txtfrm.cxx                          |   10 -
 sw/source/core/tox/txmsrt.cxx                           |   10 -
 sw/source/core/txtnode/atrfld.cxx                       |   10 -
 sw/source/core/txtnode/atrflyin.cxx                     |    8 
 sw/source/core/txtnode/atrftn.cxx                       |   16 -
 sw/source/core/txtnode/fmtatr2.cxx                      |    4 
 sw/source/core/txtnode/modeltoviewhelper.cxx            |    6 
 sw/source/core/txtnode/ndtxt.cxx                        |  154 +++++++---------
 sw/source/core/txtnode/thints.cxx                       |  116 ++++++------
 sw/source/core/txtnode/txtatr2.cxx                      |   34 +--
 sw/source/core/txtnode/txtedt.cxx                       |   45 ++--
 sw/source/core/undo/rolbck.cxx                          |    8 
 sw/source/core/undo/undobj.cxx                          |   16 -
 sw/source/core/undo/unins.cxx                           |    8 
 sw/source/core/undo/unnum.cxx                           |    4 
 sw/source/core/undo/unsect.cxx                          |    2 
 sw/source/core/undo/unsort.cxx                          |    2 
 sw/source/core/undo/untbl.cxx                           |   16 -
 sw/source/core/unocore/unocrsr.cxx                      |    4 
 sw/source/core/unocore/unocrsrhelper.cxx                |    2 
 sw/source/core/unocore/unodraw.cxx                      |    2 
 sw/source/core/unocore/unofield.cxx                     |    4 
 sw/source/core/unocore/unoflatpara.cxx                  |   12 -
 sw/source/core/unocore/unoframe.cxx                     |    2 
 sw/source/core/unocore/unoobj2.cxx                      |    8 
 sw/source/core/unocore/unoparagraph.cxx                 |    6 
 sw/source/core/unocore/unorefmk.cxx                     |   14 -
 sw/source/filter/ascii/ascatr.cxx                       |    4 
 sw/source/filter/html/htmlatr.cxx                       |    2 
 sw/source/filter/html/htmlnum.cxx                       |    2 
 sw/source/filter/html/htmlplug.cxx                      |    2 
 sw/source/filter/html/htmltab.cxx                       |    6 
 sw/source/filter/ww8/writerhelper.cxx                   |    6 
 sw/source/filter/ww8/writerwordglue.cxx                 |   10 -
 sw/source/filter/ww8/wrtw8nds.cxx                       |    2 
 sw/source/filter/xml/xmltbli.cxx                        |   12 -
 sw/source/uibase/docvw/AnnotationWin2.cxx               |    2 
 sw/source/uibase/docvw/PageBreakWin.cxx                 |    6 
 102 files changed, 699 insertions(+), 741 deletions(-)

New commits:
commit 55dfe2c12e450a90cbc05f9ec53f1ed6508d8de9
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Tue Sep 29 20:50:43 2020 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Wed Sep 30 09:46:21 2020 +0200

    SwNode::GetDoc can return a reference instead
    
    and remove discovered redundant null checks
    
    Change-Id: I6b8bc9593434f38947e399a48888a8fa0d4f7e77
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103640
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sw/inc/htmltbl.hxx b/sw/inc/htmltbl.hxx
index 622557ab81e2..8f289c39d35d 100644
--- a/sw/inc/htmltbl.hxx
+++ b/sw/inc/htmltbl.hxx
@@ -233,7 +233,7 @@ class SwHTMLTableLayout
 
     const SwStartNode *GetAnyBoxStartNode() const;
     SwFrameFormat *FindFlyFrameFormat() const;
-    const SwDoc *GetDoc() const { return GetAnyBoxStartNode()->GetDoc(); }
+    const SwDoc *GetDoc() const { return &GetAnyBoxStartNode()->GetDoc(); }
 
     void Resize_( sal_uInt16 nAbsAvail, bool bRecalc );
 
diff --git a/sw/inc/node.hxx b/sw/inc/node.hxx
index d3cb879275de..c8c1c704f00f 100644
--- a/sw/inc/node.hxx
+++ b/sw/inc/node.hxx
@@ -207,8 +207,16 @@ public:
     /// Node is in which nodes-array/doc?
     inline          SwNodes& GetNodes();
     inline const  SwNodes& GetNodes() const;
-    inline            SwDoc* GetDoc();
-    inline const  SwDoc* GetDoc() const;
+
+    SwDoc& GetDoc()
+    {
+        return GetNodes().GetDoc();
+    }
+
+    const SwDoc& GetDoc() const
+    {
+        return GetNodes().GetDoc();
+    }
 
     /** Provides access to the document setting interface
      */
@@ -699,15 +707,6 @@ inline const SwNodes& SwNode::GetNodes() const
     return static_cast<SwNodes&>(GetArray());
 }
 
-inline SwDoc* SwNode::GetDoc()
-{
-    return &GetNodes().GetDoc();
-}
-inline const SwDoc* SwNode::GetDoc() const
-{
-    return &GetNodes().GetDoc();
-}
-
 inline SwFormatColl* SwContentNode::GetCondFormatColl() const
 {
     return m_pCondColl;
diff --git a/sw/inc/pam.hxx b/sw/inc/pam.hxx
index f94c796d1bfb..6c87f3559b78 100644
--- a/sw/inc/pam.hxx
+++ b/sw/inc/pam.hxx
@@ -240,7 +240,7 @@ public:
     void Normalize(bool bPointFirst = true);
 
     /// @return the document (SwDoc) at which the PaM is registered
-    SwDoc* GetDoc() const   { return m_pPoint->nNode.GetNode().GetDoc(); }
+    SwDoc* GetDoc() const   { return &m_pPoint->nNode.GetNode().GetDoc(); }
 
           SwPosition& GetBound( bool bOne = true )
                             { return bOne ? m_Bound1 : m_Bound2; }
diff --git a/sw/source/core/SwNumberTree/SwNodeNum.cxx 
b/sw/source/core/SwNumberTree/SwNodeNum.cxx
index 38c00087bd52..795d1c8b8745 100644
--- a/sw/source/core/SwNumberTree/SwNodeNum.cxx
+++ b/sw/source/core/SwNumberTree/SwNodeNum.cxx
@@ -345,7 +345,7 @@ void SwNodeNum::UnregisterMeAndChildrenDueToRootDelete( 
SwNodeNum& rNodeNum )
     aResetAttrsArray.insert( aResetAttrsArray.end(), RES_PARATR_LIST_ISCOUNTED 
);
     aResetAttrsArray.insert( aResetAttrsArray.end(), RES_PARATR_NUMRULE );
     SwPaM aPam( *pTextNode );
-    pTextNode->GetDoc()->ResetAttrs( aPam, false,
+    pTextNode->GetDoc().ResetAttrs( aPam, false,
                                     aResetAttrsArray,
                                     false );
 }
diff --git a/sw/source/core/access/AccessibilityCheck.cxx 
b/sw/source/core/access/AccessibilityCheck.cxx
index 72c127ae6b8c..ea8034152ce8 100644
--- a/sw/source/core/access/AccessibilityCheck.cxx
+++ b/sw/source/core/access/AccessibilityCheck.cxx
@@ -94,7 +94,7 @@ class NoTextNodeAltTextCheck : public NodeCheck
         {
             auto pIssue = lclAddIssue(m_rIssueCollection, sIssueText,
                                       sfx::AccessibilityIssueID::NO_ALT_OLE);
-            pIssue->setDoc(pNoTextNode->GetDoc());
+            pIssue->setDoc(&pNoTextNode->GetDoc());
             pIssue->setIssueObject(IssueObject::OLE);
             pIssue->setObjectID(pNoTextNode->GetFlyFormat()->GetName());
         }
@@ -102,7 +102,7 @@ class NoTextNodeAltTextCheck : public NodeCheck
         {
             auto pIssue = lclAddIssue(m_rIssueCollection, sIssueText,
                                       
sfx::AccessibilityIssueID::NO_ALT_GRAPHIC);
-            pIssue->setDoc(pNoTextNode->GetDoc());
+            pIssue->setDoc(&pNoTextNode->GetDoc());
             pIssue->setIssueObject(IssueObject::GRAPHIC);
             pIssue->setObjectID(pNoTextNode->GetFlyFormat()->GetName());
         }
@@ -129,14 +129,14 @@ public:
 class TableNodeMergeSplitCheck : public NodeCheck
 {
 private:
-    void addTableIssue(SwTable const& rTable, SwDoc* pDoc)
+    void addTableIssue(SwTable const& rTable, SwDoc& rDoc)
     {
         const SwTableFormat* pFormat = rTable.GetFrameFormat();
         OUString sName = pFormat->GetName();
         OUString sIssueText = 
SwResId(STR_TABLE_MERGE_SPLIT).replaceAll("%OBJECT_NAME%", sName);
         auto pIssue = lclAddIssue(m_rIssueCollection, sIssueText,
                                   
sfx::AccessibilityIssueID::TABLE_MERGE_SPLIT);
-        pIssue->setDoc(pDoc);
+        pIssue->setDoc(&rDoc);
         pIssue->setIssueObject(IssueObject::TABLE);
         pIssue->setObjectID(sName);
     }
@@ -147,10 +147,10 @@ private:
             return;
 
         SwTable const& rTable = pTableNode->GetTable();
-        SwDoc* pDoc = pTableNode->GetDoc();
+        SwDoc& rDoc = pTableNode->GetDoc();
         if (rTable.IsTableComplex())
         {
-            addTableIssue(rTable, pDoc);
+            addTableIssue(rTable, rDoc);
         }
         else
         {
@@ -186,7 +186,7 @@ private:
                 }
                 if (!bAllColumnsSameSize || bCellSpansOverMoreRows)
                 {
-                    addTableIssue(rTable, pDoc);
+                    addTableIssue(rTable, rDoc);
                 }
             }
         }
@@ -285,7 +285,7 @@ public:
 
         SwTextNode* pTextNode = pCurrent->GetTextNode();
         uno::Reference<text::XTextContent> xParagraph
-            = SwXParagraph::CreateXParagraph(*pTextNode->GetDoc(), pTextNode);
+            = SwXParagraph::CreateXParagraph(pTextNode->GetDoc(), pTextNode);
         if (!xParagraph.is())
             return;
 
@@ -422,7 +422,7 @@ public:
 
         SwTextNode* pTextNode = pCurrent->GetTextNode();
         uno::Reference<text::XTextContent> xParagraph;
-        xParagraph = SwXParagraph::CreateXParagraph(*pTextNode->GetDoc(), 
pTextNode);
+        xParagraph = SwXParagraph::CreateXParagraph(pTextNode->GetDoc(), 
pTextNode);
         if (!xParagraph.is())
             return;
 
@@ -526,8 +526,8 @@ public:
                                   sfx::AccessibilityIssueID::TEXT_FORMATTING);
         pIssue->setIssueObject(IssueObject::TEXT);
         pIssue->setNode(pTextNode);
-        SwDoc* pDocument = pTextNode->GetDoc();
-        pIssue->setDoc(pDocument);
+        SwDoc& rDocument = pTextNode->GetDoc();
+        pIssue->setDoc(&rDocument);
         pIssue->setStart(pTextAttr->GetStart());
         pIssue->setEnd(pTextAttr->GetAnyEnd());
     }
@@ -583,7 +583,7 @@ public:
 
         SwTextNode* pTextNode = pCurrent->GetTextNode();
         uno::Reference<text::XTextContent> xParagraph;
-        xParagraph = SwXParagraph::CreateXParagraph(*pTextNode->GetDoc(), 
pTextNode);
+        xParagraph = SwXParagraph::CreateXParagraph(pTextNode->GetDoc(), 
pTextNode);
         if (!xParagraph.is())
             return;
 
diff --git a/sw/source/core/access/accpara.cxx 
b/sw/source/core/access/accpara.cxx
index 1a543581f253..7a8fb42f0c7a 100644
--- a/sw/source/core/access/accpara.cxx
+++ b/sw/source/core/access/accpara.cxx
@@ -1452,14 +1452,14 @@ void SwAccessibleParagraph::_getDefaultAttributesImpl(
     std::unique_ptr<SfxItemSet> pSet;
     if ( !bOnlyCharAttrs )
     {
-        pSet.reset( new SfxItemSet( 
const_cast<SwAttrPool&>(pTextNode->GetDoc()->GetAttrPool()),
+        pSet.reset( new SfxItemSet( 
const_cast<SwAttrPool&>(pTextNode->GetDoc().GetAttrPool()),
                                svl::Items<RES_CHRATR_BEGIN, RES_CHRATR_END - 1,
                                RES_PARATR_BEGIN, RES_PARATR_END - 1,
                                RES_FRMATR_BEGIN, RES_FRMATR_END - 1>{} ) );
     }
     else
     {
-        pSet.reset( new SfxItemSet( 
const_cast<SwAttrPool&>(pTextNode->GetDoc()->GetAttrPool()),
+        pSet.reset( new SfxItemSet( 
const_cast<SwAttrPool&>(pTextNode->GetDoc().GetAttrPool()),
                                svl::Items<RES_CHRATR_BEGIN, RES_CHRATR_END - 
1>{} ) );
     }
     // #i82637# - From the perspective of the a11y API the default character
@@ -1470,7 +1470,7 @@ void SwAccessibleParagraph::_getDefaultAttributesImpl(
     // get default paragraph attributes, if needed, and merge these into <pSet>
     if ( !bOnlyCharAttrs )
     {
-        SfxItemSet aParaSet( 
const_cast<SwAttrPool&>(pTextNode->GetDoc()->GetAttrPool()),
+        SfxItemSet aParaSet( 
const_cast<SwAttrPool&>(pTextNode->GetDoc().GetAttrPool()),
                              svl::Items<RES_PARATR_BEGIN, RES_PARATR_END - 1,
                              RES_FRMATR_BEGIN, RES_FRMATR_END - 1>{} );
         pTextNode->SwContentNode::GetAttr( aParaSet );
@@ -1481,7 +1481,7 @@ void SwAccessibleParagraph::_getDefaultAttributesImpl(
             "<SwAccessibleParagraph::_getDefaultAttributesImpl(..)> - missing 
paragraph style. Serious defect!" );
     if ( pTextNode->GetTextColl() )
     {
-        SfxItemSet aCharSet( 
const_cast<SwAttrPool&>(pTextNode->GetDoc()->GetAttrPool()),
+        SfxItemSet aCharSet( 
const_cast<SwAttrPool&>(pTextNode->GetDoc().GetAttrPool()),
                              svl::Items<RES_CHRATR_BEGIN, RES_CHRATR_END - 
1>{} );
         SetPutRecursive( aCharSet, pTextNode->GetTextColl()->GetAttrSet() );
         pSet->Put( aCharSet );
@@ -1762,7 +1762,7 @@ void 
SwAccessibleParagraph::_getSupplementalAttributesImpl(
     std::unique_ptr<SfxItemSet> pSet;
     pSet.reset(
         new SfxItemSet(
-            const_cast<SwAttrPool&>(pTextNode->GetDoc()->GetAttrPool()),
+            const_cast<SwAttrPool&>(pTextNode->GetDoc().GetAttrPool()),
             svl::Items<
                 RES_PARATR_LINESPACING, RES_PARATR_ADJUST,
                 RES_PARATR_TABSTOP, RES_PARATR_TABSTOP,
diff --git a/sw/source/core/attr/cellatr.cxx b/sw/source/core/attr/cellatr.cxx
index b7e4f507f0c2..9fbd1f9e77db 100644
--- a/sw/source/core/attr/cellatr.cxx
+++ b/sw/source/core/attr/cellatr.cxx
@@ -121,7 +121,7 @@ void SwTableBoxFormula::ChangeState( const SfxPoolItem* 
pItem )
     // detect table that contains this attribute
     const SwTableNode* pTableNd;
     const SwNode* pNd = GetNodeOfFormula();
-    if (!pNd || &pNd->GetNodes() != &pNd->GetDoc()->GetNodes())
+    if (!pNd || &pNd->GetNodes() != &pNd->GetDoc().GetNodes())
         return;
     pTableNd = pNd->FindTableNode();
     if( pTableNd == nullptr )
diff --git a/sw/source/core/attr/swatrset.cxx b/sw/source/core/attr/swatrset.cxx
index aa6d9f1ad088..35f711297789 100644
--- a/sw/source/core/attr/swatrset.cxx
+++ b/sw/source/core/attr/swatrset.cxx
@@ -299,7 +299,7 @@ void SwAttrSet::CopyToModify( SwModify& rMod ) const
 
             const SfxPoolItem* pItem;
             const SwDoc *pSrcDoc = GetDoc();
-            SwDoc *pDstDoc = pCNd ? pCNd->GetDoc() : pFormat->GetDoc();
+            SwDoc *pDstDoc = pCNd ? &pCNd->GetDoc() : pFormat->GetDoc();
 
             // Does the NumRule has to be copied?
             if( pSrcDoc != pDstDoc &&
diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
index 4398607ce0f7..7c7471b081b5 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -738,7 +738,7 @@ static SwFrame* lcl_IsInHeaderFooter( const SwNodeIndex& 
rIdx, Point& rPt )
     {
         std::pair<Point, bool> tmp(rPt, false);
         SwContentFrame *pContentFrame = pCNd->getLayoutFrame(
-            pCNd->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout(),
+            pCNd->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout(),
             nullptr, &tmp);
         pFrame = pContentFrame ? pContentFrame->GetUpper() : nullptr;
         while( pFrame && !pFrame->IsHeaderFrame() && !pFrame->IsFooterFrame() )
@@ -3688,7 +3688,7 @@ static void lcl_FillTextRange( 
uno::Reference<text::XTextRange>& rRange,
     aEndPos.nContent = nBegin + nLen;
 
     const uno::Reference<text::XTextRange> xRange =
-        SwXTextRange::CreateXTextRange(*rNode.GetDoc(), aStartPos, &aEndPos);
+        SwXTextRange::CreateXTextRange(rNode.GetDoc(), aStartPos, &aEndPos);
 
     rRange = xRange;
 }
diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx
index 38676f772659..804bdab8a05a 100644
--- a/sw/source/core/crsr/crstrvl.cxx
+++ b/sw/source/core/crsr/crstrvl.cxx
@@ -644,7 +644,7 @@ static void lcl_MakeFieldLst(
             std::pair<Point, bool> const tmp(aPt, false);
             const SwContentFrame* pCFrame =
                 rTextNode.getLayoutFrame(
-                    
rTextNode.GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout(),
+                    
rTextNode.GetDoc().getIDocumentLayoutAccess().GetCurrentLayout(),
                     nullptr, &tmp);
             if ( pCFrame != nullptr
                  && ( bInReadOnly || !pCFrame->IsProtected() ) )
@@ -1900,7 +1900,7 @@ bool SwContentAtPos::IsInProtectSect() const
     if( pNd->IsInProtectSect() )
         return true;
 
-    const SwContentFrame* pFrame = 
pNd->getLayoutFrame(pNd->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout(),
 nullptr, nullptr);
+    const SwContentFrame* pFrame = 
pNd->getLayoutFrame(pNd->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout(),
 nullptr, nullptr);
     return pFrame && pFrame->IsProtected() ;
 }
 
diff --git a/sw/source/core/crsr/findtxt.cxx b/sw/source/core/crsr/findtxt.cxx
index 1e9ecef2c2d2..047e3db0127b 100644
--- a/sw/source/core/crsr/findtxt.cxx
+++ b/sw/source/core/crsr/findtxt.cxx
@@ -505,7 +505,7 @@ bool FindTextImpl(SwPaM & rSearchPam,
 
             }
 
-            SwDocShell *const pDocShell = pNode->GetDoc()->GetDocShell();
+            SwDocShell *const pDocShell = pNode->GetDoc().GetDocShell();
             SwWrtShell *const pWrtShell = pDocShell ? pDocShell->GetWrtShell() 
: nullptr;
             SwPostItMgr *const pPostItMgr = pWrtShell ? 
pWrtShell->GetPostItMgr() : nullptr;
 
@@ -557,7 +557,7 @@ bool FindTextImpl(SwPaM & rSearchPam,
                 if (!bEndedTextEdit && !(pSearchItem && 
pSearchItem->GetCommand() == SvxSearchCmd::FIND_ALL))
                 {
                     // If there are any shapes anchored to this node, search 
there.
-                    SwPaM aPaM(pNode->GetDoc()->GetNodes().GetEndOfContent());
+                    SwPaM aPaM(pNode->GetDoc().GetNodes().GetEndOfContent());
                     if (pLayout)
                     {
                         *aPaM.GetPoint() = 
pFrame->MapViewToModelPos(nStart.GetFrameIndex());
@@ -582,7 +582,7 @@ bool FindTextImpl(SwPaM & rSearchPam,
                         aPaM.GetMark()->nNode = rTextNode.GetIndex() + 1;
                     }
                     
aPaM.GetMark()->nContent.Assign(aPaM.GetMark()->nNode.GetNode().GetTextNode(), 
0);
-                    if 
(pNode->GetDoc()->getIDocumentDrawModelAccess().Search(aPaM, *xSearchItem) && 
pSdrView)
+                    if 
(pNode->GetDoc().getIDocumentDrawModelAccess().Search(aPaM, *xSearchItem) && 
pSdrView)
                     {
                         if (SdrObject* pObject = pSdrView->GetTextEditObject())
                         {
diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx
index 0473d8bacfd1..fb7aa7cd38a5 100644
--- a/sw/source/core/crsr/pam.cxx
+++ b/sw/source/core/crsr/pam.cxx
@@ -177,7 +177,7 @@ bool SwPosition::operator!=(const SwPosition &rPos) const
 
 SwDoc * SwPosition::GetDoc() const
 {
-    return nNode.GetNode().GetDoc();
+    return &nNode.GetNode().GetDoc();
 }
 
 void SwPosition::dumpAsXml(xmlTextWriterPtr pWriter) const
@@ -560,7 +560,7 @@ sal_uInt16 SwPaM::GetPageNum( bool bAtPoint, const Point* 
pLayPos )
         tmp.second = false;
     }
     if( nullptr != ( pNd = pPos->nNode.GetNode().GetContentNode() ) &&
-        nullptr != (pCFrame = 
pNd->getLayoutFrame(pNd->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout(),
 pPos, pLayPos ? &tmp : nullptr)) &&
+        nullptr != (pCFrame = 
pNd->getLayoutFrame(pNd->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout(),
 pPos, pLayPos ? &tmp : nullptr)) &&
         nullptr != ( pPg = pCFrame->FindPageFrame() ))
         return pPg->GetPhyPageNum();
     return 0;
@@ -603,7 +603,7 @@ bool SwPaM::HasReadonlySel( bool bFormView ) const
         Point aTmpPt;
         std::pair<Point, bool> const tmp(aTmpPt, false);
         pFrame = pNd->getLayoutFrame(
-            pNd->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout(),
+            pNd->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout(),
             GetPoint(), &tmp);
     }
 
@@ -649,7 +649,7 @@ bool SwPaM::HasReadonlySel( bool bFormView ) const
             Point aTmpPt;
             std::pair<Point, bool> const tmp(aTmpPt, false);
             pFrame = pNd->getLayoutFrame(
-                pNd->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout(),
+                pNd->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout(),
                 GetMark(), &tmp);
         }
 
diff --git a/sw/source/core/crsr/swcrsr.cxx b/sw/source/core/crsr/swcrsr.cxx
index dbb60e5ea6bc..2e1a19338a52 100644
--- a/sw/source/core/crsr/swcrsr.cxx
+++ b/sw/source/core/crsr/swcrsr.cxx
@@ -1527,7 +1527,7 @@ static OUString lcl_MaskDeletedRedlines( const 
SwTextNode* pTextNd )
     {
         //mask deleted redlines
         OUString sNodeText(pTextNd->GetText());
-        const SwDoc& rDoc = *pTextNd->GetDoc();
+        const SwDoc& rDoc = pTextNd->GetDoc();
         const bool bShowChg = IDocumentRedlineAccess::IsShowChanges( 
rDoc.getIDocumentRedlineAccess().GetRedlineFlags() );
         if ( bShowChg )
         {
diff --git a/sw/source/core/crsr/trvlfnfl.cxx b/sw/source/core/crsr/trvlfnfl.cxx
index ad7f956a2af3..9baa0761c06a 100644
--- a/sw/source/core/crsr/trvlfnfl.cxx
+++ b/sw/source/core/crsr/trvlfnfl.cxx
@@ -138,7 +138,7 @@ bool SwCursor::GotoFootnoteAnchor()
     if( pSttNd )
     {
         // search in all footnotes in document for this StartIndex
-        const SwFootnoteIdxs& rFootnoteArr = 
pSttNd->GetDoc()->GetFootnoteIdxs();
+        const SwFootnoteIdxs& rFootnoteArr = 
pSttNd->GetDoc().GetFootnoteIdxs();
         for( size_t n = 0; n < rFootnoteArr.size(); ++n )
         {
             const SwTextFootnote* pTextFootnote = rFootnoteArr[ n ];
diff --git a/sw/source/core/crsr/trvltbl.cxx b/sw/source/core/crsr/trvltbl.cxx
index 9ce51c029576..533f17907b05 100644
--- a/sw/source/core/crsr/trvltbl.cxx
+++ b/sw/source/core/crsr/trvltbl.cxx
@@ -369,7 +369,7 @@ static bool lcl_FindNextCell( SwNodeIndex& rIdx, bool 
bInReadOnly )
     if ( !pCNd )
         return false;
 
-    SwContentFrame* pFrame = pCNd->getLayoutFrame( 
pCNd->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout() );
+    SwContentFrame* pFrame = pCNd->getLayoutFrame( 
pCNd->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout() );
 
     if ( nullptr == pFrame || pCNd->FindTableNode() != pTableNd ||
         (!bInReadOnly && pFrame->IsProtected() ) )
@@ -401,7 +401,7 @@ static bool lcl_FindNextCell( SwNodeIndex& rIdx, bool 
bInReadOnly )
                 return false;
 
             // check if we have found a suitable table cell:
-            pFrame = pCNd->getLayoutFrame( 
pCNd->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout() );
+            pFrame = pCNd->getLayoutFrame( 
pCNd->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout() );
 
             if ( nullptr != pFrame && pCNd->FindTableNode() == pTableNd &&
                 (bInReadOnly || !pFrame->IsProtected() ) )
@@ -441,7 +441,7 @@ static bool lcl_FindPrevCell( SwNodeIndex& rIdx, bool 
bInReadOnly  )
     if ( !pCNd )
         return false;
 
-    SwContentFrame* pFrame = pCNd->getLayoutFrame( 
pCNd->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout() );
+    SwContentFrame* pFrame = pCNd->getLayoutFrame( 
pCNd->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout() );
 
     if( nullptr == pFrame || pCNd->FindTableNode() != pTableNd ||
         (!bInReadOnly && pFrame->IsProtected() ))
@@ -462,7 +462,7 @@ static bool lcl_FindPrevCell( SwNodeIndex& rIdx, bool 
bInReadOnly  )
             if ( !pCNd )
                 return false;
 
-            pFrame = pCNd->getLayoutFrame( 
pCNd->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout() );
+            pFrame = pCNd->getLayoutFrame( 
pCNd->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout() );
 
             if( nullptr != pFrame && pCNd->FindTableNode() == pTableNd &&
                 (bInReadOnly || !pFrame->IsProtected() ) )
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
index 3479e62c2c37..9a949d6479a2 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -371,7 +371,7 @@ static SwRect lcl_getLayoutRect(const Point& rPoint, const 
SwPosition& rPosition
     const SwContentNode* pNode = rPosition.nNode.GetNode().GetContentNode();
     std::pair<Point, bool> const tmp(rPoint, true);
     const SwContentFrame* pFrame = pNode->getLayoutFrame(
-            pNode->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout(),
+            pNode->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout(),
             &rPosition, &tmp);
     SwRect aRect;
     pFrame->GetCharRect(aRect, rPosition);
diff --git a/sw/source/core/doc/CntntIdxStore.cxx 
b/sw/source/core/doc/CntntIdxStore.cxx
index bc60a0de37a6..57e700182662 100644
--- a/sw/source/core/doc/CntntIdxStore.cxx
+++ b/sw/source/core/doc/CntntIdxStore.cxx
@@ -167,18 +167,18 @@ namespace
         virtual void Restore(SwNode& rNd, sal_Int32 nLen, sal_Int32 nCorrLen, 
RestoreMode eMode = RestoreMode::All) override
         {
             SwContentNode* pCNd = rNd.GetContentNode();
-            SwDoc* pDoc = rNd.GetDoc();
+            SwDoc& rDoc = rNd.GetDoc();
             updater_t aUpdater = LimitUpdater(pCNd, nLen, nCorrLen);
             if (eMode & RestoreMode::NonFlys)
             {
-                RestoreBkmks(pDoc, aUpdater);
-                RestoreRedlines(pDoc, aUpdater);
+                RestoreBkmks(&rDoc, aUpdater);
+                RestoreRedlines(&rDoc, aUpdater);
                 RestoreUnoCursors(aUpdater);
                 RestoreShellCursors(aUpdater);
             }
             if (eMode & RestoreMode::Flys)
             {
-                RestoreFlys(pDoc, aUpdater, false);
+                RestoreFlys(&rDoc, aUpdater, false);
             }
         }
 
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx 
b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index 558db3827522..267a02c0a1d4 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -99,10 +99,10 @@ namespace
 {
     // Copy method from SwDoc
     // Prevent copying into Flys that are anchored in the range
-    bool lcl_ChkFlyFly( SwDoc* pDoc, sal_uLong nSttNd, sal_uLong nEndNd,
+    bool lcl_ChkFlyFly( SwDoc& rDoc, sal_uLong nSttNd, sal_uLong nEndNd,
                         sal_uLong nInsNd )
     {
-        const SwFrameFormats& rFrameFormatTable = *pDoc->GetSpzFrameFormats();
+        const SwFrameFormats& rFrameFormatTable = *rDoc.GetSpzFrameFormats();
 
         for( size_t n = 0; n < rFrameFormatTable.size(); ++n )
         {
@@ -128,7 +128,7 @@ namespace
                     // Do not copy !
                     return true;
 
-                if( lcl_ChkFlyFly( pDoc, pSNd->GetIndex(),
+                if( lcl_ChkFlyFly( rDoc, pSNd->GetIndex(),
                             pSNd->EndOfSectionIndex(), nInsNd ) )
                     // Do not copy !
                     return true;
@@ -422,8 +422,8 @@ namespace
 
     void lcl_DeleteRedlines( const SwNodeRange& rRg, SwNodeRange const & 
rCpyRg )
     {
-        SwDoc* pSrcDoc = rRg.aStart.GetNode().GetDoc();
-        if( !pSrcDoc->getIDocumentRedlineAccess().GetRedlineTable().empty() )
+        SwDoc& rSrcDoc = rRg.aStart.GetNode().GetDoc();
+        if( !rSrcDoc.getIDocumentRedlineAccess().GetRedlineTable().empty() )
         {
             SwPaM aRgTmp( rRg.aStart, rRg.aEnd );
             SwPaM aCpyTmp( rCpyRg.aStart, rCpyRg.aEnd );
@@ -770,24 +770,24 @@ namespace
 
     void lcl_SaveRedlines(const SwPaM& aPam, SaveRedlines_t& rArr)
     {
-        SwDoc* pDoc = aPam.GetNode().GetDoc();
+        SwDoc& rDoc = aPam.GetNode().GetDoc();
 
         const SwPosition* pStart = aPam.Start();
         const SwPosition* pEnd = aPam.End();
 
         // get first relevant redline
         SwRedlineTable::size_type nCurrentRedline;
-        pDoc->getIDocumentRedlineAccess().GetRedline( *pStart, 
&nCurrentRedline );
+        rDoc.getIDocumentRedlineAccess().GetRedline( *pStart, &nCurrentRedline 
);
         if( nCurrentRedline > 0)
             nCurrentRedline--;
 
         // redline mode RedlineFlags::Ignore|RedlineFlags::On; save old mode
-        RedlineFlags eOld = 
pDoc->getIDocumentRedlineAccess().GetRedlineFlags();
-        pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( ( eOld & 
~RedlineFlags::Ignore) | RedlineFlags::On );
+        RedlineFlags eOld = rDoc.getIDocumentRedlineAccess().GetRedlineFlags();
+        rDoc.getIDocumentRedlineAccess().SetRedlineFlags_intern( ( eOld & 
~RedlineFlags::Ignore) | RedlineFlags::On );
 
         // iterate over relevant redlines and decide for each whether it should
         // be saved, or split + saved
-        SwRedlineTable& rRedlineTable = 
pDoc->getIDocumentRedlineAccess().GetRedlineTable();
+        SwRedlineTable& rRedlineTable = 
rDoc.getIDocumentRedlineAccess().GetRedlineTable();
         for( ; nCurrentRedline < rRedlineTable.size(); nCurrentRedline++ )
         {
             SwRangeRedline* pCurrent = rRedlineTable[ nCurrentRedline ];
@@ -812,7 +812,7 @@ namespace
                     SwRangeRedline* pNewRedline = new SwRangeRedline( 
*pCurrent );
                     *pNewRedline->End() = *pStart;
                     *pCurrent->Start() = *pStart;
-                    pDoc->getIDocumentRedlineAccess().AppendRedline( 
pNewRedline, true );
+                    rDoc.getIDocumentRedlineAccess().AppendRedline( 
pNewRedline, true );
                 }
 
                 // split end, if necessary
@@ -822,7 +822,7 @@ namespace
                     SwRangeRedline* pNewRedline = new SwRangeRedline( 
*pCurrent );
                     *pNewRedline->Start() = *pEnd;
                     *pCurrent->End() = *pEnd;
-                    pDoc->getIDocumentRedlineAccess().AppendRedline( 
pNewRedline, true );
+                    rDoc.getIDocumentRedlineAccess().AppendRedline( 
pNewRedline, true );
                 }
 
                 // save the current redline
@@ -831,7 +831,7 @@ namespace
         }
 
         // restore old redline mode
-        pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld );
+        rDoc.getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld );
     }
 
     void lcl_RestoreRedlines(SwDoc* pDoc, const SwPosition& rPos, 
SaveRedlines_t& rArr)
@@ -850,18 +850,18 @@ namespace
 
     void lcl_SaveRedlines(const SwNodeRange& rRg, SaveRedlines_t& rArr)
     {
-        SwDoc* pDoc = rRg.aStart.GetNode().GetDoc();
+        SwDoc& rDoc = rRg.aStart.GetNode().GetDoc();
         SwRedlineTable::size_type nRedlPos;
         SwPosition aSrchPos( rRg.aStart ); aSrchPos.nNode--;
         aSrchPos.nContent.Assign( aSrchPos.nNode.GetNode().GetContentNode(), 0 
);
-        if( pDoc->getIDocumentRedlineAccess().GetRedline( aSrchPos, &nRedlPos 
) && nRedlPos )
+        if( rDoc.getIDocumentRedlineAccess().GetRedline( aSrchPos, &nRedlPos ) 
&& nRedlPos )
             --nRedlPos;
-        else if( nRedlPos >= 
pDoc->getIDocumentRedlineAccess().GetRedlineTable().size() )
+        else if( nRedlPos >= 
rDoc.getIDocumentRedlineAccess().GetRedlineTable().size() )
             return ;
 
-        RedlineFlags eOld = 
pDoc->getIDocumentRedlineAccess().GetRedlineFlags();
-        pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( ( eOld & 
~RedlineFlags::Ignore) | RedlineFlags::On );
-        SwRedlineTable& rRedlTable = 
pDoc->getIDocumentRedlineAccess().GetRedlineTable();
+        RedlineFlags eOld = rDoc.getIDocumentRedlineAccess().GetRedlineFlags();
+        rDoc.getIDocumentRedlineAccess().SetRedlineFlags_intern( ( eOld & 
~RedlineFlags::Ignore) | RedlineFlags::On );
+        SwRedlineTable& rRedlTable = 
rDoc.getIDocumentRedlineAccess().GetRedlineTable();
 
         do {
             SwRangeRedline* pTmp = rRedlTable[ nRedlPos ];
@@ -921,14 +921,14 @@ namespace
                     pTmpPos->nNode = rRg.aEnd;
                     pTmpPos->nContent.Assign(
                                 pTmpPos->nNode.GetNode().GetContentNode(), 0 );
-                    pDoc->getIDocumentRedlineAccess().AppendRedline( pTmp, 
true );
+                    rDoc.getIDocumentRedlineAccess().AppendRedline( pTmp, true 
);
                 }
             }
             else
                 break;
 
-        } while( ++nRedlPos < 
pDoc->getIDocumentRedlineAccess().GetRedlineTable().size() );
-        pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld );
+        } while( ++nRedlPos < 
rDoc.getIDocumentRedlineAccess().GetRedlineTable().size() );
+        rDoc.getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld );
     }
 
     void lcl_RestoreRedlines(SwDoc *const pDoc, sal_uInt32 const nInsPos, 
SaveRedlines_t& rArr)
@@ -1895,15 +1895,15 @@ DocumentContentOperationsManager::CopyRange( SwPaM& 
rPam, SwPosition& rPos,
 {
     const SwPosition *pStt = rPam.Start(), *pEnd = rPam.End();
 
-    SwDoc* pDoc = rPos.nNode.GetNode().GetDoc();
-    bool bColumnSel = pDoc->IsClipBoard() && pDoc->IsColumnSelection();
+    SwDoc& rDoc = rPos.nNode.GetNode().GetDoc();
+    bool bColumnSel = rDoc.IsClipBoard() && rDoc.IsColumnSelection();
 
     // Catch if there's no copy to do
     if (!rPam.HasMark() || (IsEmptyRange(*pStt, *pEnd, flags) && !bColumnSel))
         return false;
 
     // Prevent copying into Flys that are anchored in the source range
-    if (pDoc == &m_rDoc && (flags & SwCopyFlags::CheckPosInFly))
+    if (&rDoc == &m_rDoc && (flags & SwCopyFlags::CheckPosInFly))
     {
         // Correct the Start-/EndNode
         sal_uLong nStt = pStt->nNode.GetIndex(),
@@ -1922,22 +1922,22 @@ DocumentContentOperationsManager::CopyRange( SwPaM& 
rPam, SwPosition& rPos,
             --nDiff;
         }
         if( nDiff &&
-            lcl_ChkFlyFly( pDoc, nStt, nEnd, rPos.nNode.GetIndex() ) )
+            lcl_ChkFlyFly( rDoc, nStt, nEnd, rPos.nNode.GetIndex() ) )
         {
             return false;
         }
     }
 
     SwPaM* pRedlineRange = nullptr;
-    if( pDoc->getIDocumentRedlineAccess().IsRedlineOn() ||
-        (!pDoc->getIDocumentRedlineAccess().IsIgnoreRedline() && 
!pDoc->getIDocumentRedlineAccess().GetRedlineTable().empty() ) )
+    if( rDoc.getIDocumentRedlineAccess().IsRedlineOn() ||
+        (!rDoc.getIDocumentRedlineAccess().IsIgnoreRedline() && 
!rDoc.getIDocumentRedlineAccess().GetRedlineTable().empty() ) )
         pRedlineRange = new SwPaM( rPos );
 
-    RedlineFlags eOld = pDoc->getIDocumentRedlineAccess().GetRedlineFlags();
+    RedlineFlags eOld = rDoc.getIDocumentRedlineAccess().GetRedlineFlags();
 
     bool bRet = false;
 
-    if( pDoc != &m_rDoc )
+    if( &rDoc != &m_rDoc )
     {   // ordinary copy
         bRet = CopyImpl(rPam, rPos, flags & ~SwCopyFlags::CheckPosInFly, 
pRedlineRange);
     }
@@ -1955,13 +1955,13 @@ DocumentContentOperationsManager::CopyRange( SwPaM& 
rPam, SwPosition& rPos,
         assert(!"mst: this is assumed to be dead code");
     }
 
-    pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld );
+    rDoc.getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld );
     if( pRedlineRange )
     {
-        if( pDoc->getIDocumentRedlineAccess().IsRedlineOn() )
-            pDoc->getIDocumentRedlineAccess().AppendRedline( new 
SwRangeRedline( RedlineType::Insert, *pRedlineRange ), true);
+        if( rDoc.getIDocumentRedlineAccess().IsRedlineOn() )
+            rDoc.getIDocumentRedlineAccess().AppendRedline( new 
SwRangeRedline( RedlineType::Insert, *pRedlineRange ), true);
         else
-            pDoc->getIDocumentRedlineAccess().SplitRedline( *pRedlineRange );
+            rDoc.getIDocumentRedlineAccess().SplitRedline( *pRedlineRange );
         delete pRedlineRange;
     }
 
@@ -3472,7 +3472,7 @@ void DocumentContentOperationsManager::CopyWithFlyInFly(
     assert(!pCopiedPaM || pCopiedPaM->first.End()->nNode == rRg.aEnd);
     assert(!pCopiedPaM || pCopiedPaM->second.nNode <= rInsPos);
 
-    SwDoc* pDest = rInsPos.GetNode().GetDoc();
+    SwDoc& rDest = rInsPos.GetNode().GetDoc();
     SwNodeIndex aSavePos( rInsPos );
 
     if (rRg.aStart != rRg.aEnd)
@@ -3536,7 +3536,7 @@ void DocumentContentOperationsManager::CopyWithFlyInFly(
             SwNodeIndex const end(rInsPos,
                     (!isRecreateEndNode || isAtStartOfSection)
                     ? 0 : +1);
-            ::MakeFrames(pDest, aSavePos, end);
+            ::MakeFrames(&rDest, aSavePos, end);
         }
         if (bEndIsEqualEndPos)
         {
@@ -3566,7 +3566,7 @@ void DocumentContentOperationsManager::CopyWithFlyInFly(
 #endif
 
     {
-        ::sw::UndoGuard const undoGuard(pDest->GetIDocumentUndoRedo());
+        ::sw::UndoGuard const undoGuard(rDest.GetIDocumentUndoRedo());
         CopyFlyInFlyImpl(rRg, pCopiedPaM ? &pCopiedPaM->first : nullptr,
             // see comment below regarding use of pCopiedPaM->second
             (pCopiedPaM && rRg.aStart != pCopiedPaM->first.Start()->nNode)
@@ -3599,10 +3599,10 @@ void DocumentContentOperationsManager::CopyWithFlyInFly(
         sw::CopyBookmarks(pCopiedPaM ? pCopiedPaM->first : aRgTmp, 
*aCpyPaM.Start());
     }
 
-    if( bDelRedlines && ( RedlineFlags::DeleteRedlines & 
pDest->getIDocumentRedlineAccess().GetRedlineFlags() ))
+    if( bDelRedlines && ( RedlineFlags::DeleteRedlines & 
rDest.getIDocumentRedlineAccess().GetRedlineFlags() ))
         lcl_DeleteRedlines( rRg, aCpyRange );
 
-    pDest->GetNodes().DelDummyNodes( aCpyRange );
+    rDest.GetNodes().DelDummyNodes( aCpyRange );
 }
 
 // note: for the redline Show/Hide this must be in sync with
@@ -3619,7 +3619,7 @@ void DocumentContentOperationsManager::CopyFlyInFlyImpl(
     // First collect all Flys, sort them according to their ordering number,
     // and then only copy them. This maintains the ordering numbers (which are 
only
     // managed in the DrawModel).
-    SwDoc *const pDest = rStartIdx.GetNode().GetDoc();
+    SwDoc& rDest = rStartIdx.GetNode().GetDoc();
     std::set< ZSortFly > aSet;
     const size_t nArrLen = m_rDoc.GetSpzFrameFormats()->size();
 
@@ -3797,7 +3797,7 @@ void DocumentContentOperationsManager::CopyFlyInFlyImpl(
         aAnchor.SetAnchor( &newPos );
 
         // Check recursion: if copying content inside the same frame, then 
don't copy the format.
-        if( pDest == &m_rDoc )
+        if( &rDest == &m_rDoc )
         {
             const SwFormatContent& rContent = (*it).GetFormat()->GetContent();
             const SwStartNode* pSNd;
@@ -3820,7 +3820,7 @@ void DocumentContentOperationsManager::CopyFlyInFlyImpl(
         }
 
         // Copy the format and set the new anchor
-        aVecSwFrameFormat.push_back( 
pDest->getIDocumentLayoutAccess().CopyLayoutFormat( *(*it).GetFormat(),
+        aVecSwFrameFormat.push_back( 
rDest.getIDocumentLayoutAccess().CopyLayoutFormat( *(*it).GetFormat(),
                 aAnchor, false, true ) );
         ++it;
     }
@@ -4696,8 +4696,8 @@ bool 
DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
         SwCopyFlags const flags,
         SwPaM *const pCpyRange) const
 {
-    SwDoc* pDoc = rPos.nNode.GetNode().GetDoc();
-    const bool bColumnSel = pDoc->IsClipBoard() && pDoc->IsColumnSelection();
+    SwDoc& rDoc = rPos.nNode.GetNode().GetDoc();
+    const bool bColumnSel = rDoc.IsClipBoard() && rDoc.IsColumnSelection();
 
     SwPosition const*const pStt = rPam.Start();
     SwPosition *const pEnd = rPam.End();
@@ -4706,37 +4706,37 @@ bool 
DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
     if (!rPam.HasMark() || (IsEmptyRange(*pStt, *pEnd, flags) && !bColumnSel) 
||
         //JP 29.6.2001: 88963 - don't copy if inspos is in region of start to 
end
         //JP 15.11.2001: don't test inclusive the end, ever exclusive
-        ( pDoc == &m_rDoc && *pStt <= rPos && rPos < *pEnd ))
+        ( &rDoc == &m_rDoc && *pStt <= rPos && rPos < *pEnd ))
     {
         return false;
     }
 
-    const bool bEndEqualIns = pDoc == &m_rDoc && rPos == *pEnd;
+    const bool bEndEqualIns = &rDoc == &m_rDoc && rPos == *pEnd;
 
     // If Undo is enabled, create the UndoCopy object
     SwUndoCpyDoc* pUndo = nullptr;
     // lcl_DeleteRedlines may delete the start or end node of the cursor when
     // removing the redlines so use cursor that is corrected by PaMCorrAbs
-    std::shared_ptr<SwUnoCursor> const pCopyPam(pDoc->CreateUnoCursor(rPos));
+    std::shared_ptr<SwUnoCursor> const pCopyPam(rDoc.CreateUnoCursor(rPos));
 
-    SwTableNumFormatMerge aTNFM( m_rDoc, *pDoc );
+    SwTableNumFormatMerge aTNFM( m_rDoc, rDoc );
     std::unique_ptr<std::vector<SwFrameFormat*>> pFlys;
     std::vector<SwFrameFormat*> const* pFlysAtInsPos;
 
-    if (pDoc->GetIDocumentUndoRedo().DoesUndo())
+    if (rDoc.GetIDocumentUndoRedo().DoesUndo())
     {
         pUndo = new SwUndoCpyDoc(*pCopyPam);
-        pDoc->GetIDocumentUndoRedo().AppendUndo( 
std::unique_ptr<SwUndo>(pUndo) );
+        rDoc.GetIDocumentUndoRedo().AppendUndo( std::unique_ptr<SwUndo>(pUndo) 
);
         pFlysAtInsPos = pUndo->GetFlysAnchoredAt();
     }
     else
     {
-        pFlys = sw::GetFlysAnchoredAt(*pDoc, rPos.nNode.GetIndex());
+        pFlys = sw::GetFlysAnchoredAt(rDoc, rPos.nNode.GetIndex());
         pFlysAtInsPos = pFlys.get();
     }
 
-    RedlineFlags eOld = pDoc->getIDocumentRedlineAccess().GetRedlineFlags();
-    pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern(eOld | 
RedlineFlags::Ignore);
+    RedlineFlags eOld = rDoc.getIDocumentRedlineAccess().GetRedlineFlags();
+    rDoc.getIDocumentRedlineAccess().SetRedlineFlags_intern(eOld | 
RedlineFlags::Ignore);
 
     // Move the PaM one node back from the insert position, so that
     // the position doesn't get moved
@@ -4765,7 +4765,7 @@ bool 
DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
     SwTextNode* pSttTextNd = pStt->nNode.GetNode().GetTextNode();
     SwTextNode* pEndTextNd = pEnd->nNode.GetNode().GetTextNode();
     SwTextNode* pDestTextNd = aInsPos.GetNode().GetTextNode();
-    bool bCopyCollFormat = !pDoc->IsInsOnlyTextGlossary() &&
+    bool bCopyCollFormat = !rDoc.IsInsOnlyTextGlossary() &&
                         ( (pDestTextNd && !pDestTextNd->GetText().getLength()) 
||
                           ( !bOneNode && !rPos.nContent.GetIndex() ) );
     bool bCopyBookmarks = true;
@@ -4773,9 +4773,9 @@ bool 
DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
     int nDeleteTextNodes = 0;
 
     // #i104585# copy outline num rule to clipboard (for ASCII filter)
-    if (pDoc->IsClipBoard() && m_rDoc.GetOutlineNumRule())
+    if (rDoc.IsClipBoard() && m_rDoc.GetOutlineNumRule())
     {
-        pDoc->SetOutlineNumRule(*m_rDoc.GetOutlineNumRule());
+        rDoc.SetOutlineNumRule(*m_rDoc.GetOutlineNumRule());
     }
 
     // #i86492#
@@ -4785,11 +4785,11 @@ bool 
DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
     // Keep also the <ListId> value for possible propagation.
     OUString aListIdToPropagate;
     const SwNumRule* pNumRuleToPropagate =
-        pDoc->SearchNumRule( rPos, false, true, false, 0, aListIdToPropagate, 
nullptr, true );
+        rDoc.SearchNumRule( rPos, false, true, false, 0, aListIdToPropagate, 
nullptr, true );
     if ( !pNumRuleToPropagate )
     {
         pNumRuleToPropagate =
-            pDoc->SearchNumRule( rPos, false, false, false, 0, 
aListIdToPropagate, nullptr, true );
+            rDoc.SearchNumRule( rPos, false, false, false, 0, 
aListIdToPropagate, nullptr, true );
     }
     // #i86492#
     // Do not propagate previous found list, if
@@ -4816,11 +4816,11 @@ bool 
DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
                 if( !pDestTextNd )
                 {
                     if( pStt->nContent.GetIndex() || bOneNode )
-                        pDestTextNd = pDoc->GetNodes().MakeTextNode( aInsPos,
-                            
pDoc->getIDocumentStylePoolAccess().GetTextCollFromPool(RES_POOLCOLL_STANDARD));
+                        pDestTextNd = rDoc.GetNodes().MakeTextNode( aInsPos,
+                            
rDoc.getIDocumentStylePoolAccess().GetTextCollFromPool(RES_POOLCOLL_STANDARD));
                     else
                     {
-                        pDestTextNd = pSttTextNd->MakeCopy(pDoc, aInsPos, 
true)->GetTextNode();
+                        pDestTextNd = pSttTextNd->MakeCopy(&rDoc, aInsPos, 
true)->GetTextNode();
                         bCopyOk = true;
                     }
                     aDestIdx.Assign( pDestTextNd, 0 );
@@ -4830,8 +4830,8 @@ bool 
DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
                 {
                     const sal_Int32 nContentEnd = pEnd->nContent.GetIndex();
                     {
-                        ::sw::UndoGuard const ug(pDoc->GetIDocumentUndoRedo());
-                        pDoc->getIDocumentContentOperations().SplitNode( rPos, 
false );
+                        ::sw::UndoGuard const ug(rDoc.GetIDocumentUndoRedo());
+                        rDoc.getIDocumentContentOperations().SplitNode( rPos, 
false );
                     }
 
                     if (bCanMoveBack && rPos == *pCopyPam->GetPoint())
@@ -4841,7 +4841,7 @@ bool 
DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
                         pCopyPam->Move( fnMoveBackward, GoInContent );
                     }
 
-                    pDestTextNd = pDoc->GetNodes()[ aInsPos.GetIndex()-1 
]->GetTextNode();
+                    pDestTextNd = rDoc.GetNodes()[ aInsPos.GetIndex()-1 
]->GetTextNode();
                     aDestIdx.Assign(
                             pDestTextNd, pDestTextNd->GetText().getLength());
 
@@ -4897,7 +4897,7 @@ bool 
DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
                     // copy at-char flys in rPam
                     SwNodeIndex temp(*pDestTextNd); // update to new (start) 
node for flys
                     // tdf#126626 prevent duplicate Undos
-                    ::sw::UndoGuard const ug(pDoc->GetIDocumentUndoRedo());
+                    ::sw::UndoGuard const ug(rDoc.GetIDocumentUndoRedo());
                     CopyFlyInFlyImpl(aRg, &rPam, temp, false);
 
                     break;
@@ -4921,8 +4921,8 @@ bool 
DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
 
                 const sal_Int32 nContentEnd = pEnd->nContent.GetIndex();
                 {
-                    ::sw::UndoGuard const ug(pDoc->GetIDocumentUndoRedo());
-                    pDoc->getIDocumentContentOperations().SplitNode( rPos, 
false );
+                    ::sw::UndoGuard const ug(rDoc.GetIDocumentUndoRedo());
+                    rDoc.getIDocumentContentOperations().SplitNode( rPos, 
false );
                 }
 
                 if (bCanMoveBack && rPos == *pCopyPam->GetPoint())
@@ -4963,8 +4963,8 @@ bool 
DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
             SwIndex aDestIdx( rPos.nContent );
             if( !pDestTextNd )
             {
-                pDestTextNd = pDoc->GetNodes().MakeTextNode( aInsPos,
-                            
pDoc->getIDocumentStylePoolAccess().GetTextCollFromPool(RES_POOLCOLL_STANDARD));
+                pDestTextNd = rDoc.GetNodes().MakeTextNode( aInsPos,
+                            
rDoc.getIDocumentStylePoolAccess().GetTextCollFromPool(RES_POOLCOLL_STANDARD));
                 aDestIdx.Assign( pDestTextNd, 0  );
                 aInsPos--;
 
@@ -4997,7 +4997,7 @@ bool 
DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
             }
         }
 
-        SfxItemSet aBrkSet( pDoc->GetAttrPool(), aBreakSetRange );
+        SfxItemSet aBrkSet( rDoc.GetAttrPool(), aBreakSetRange );
         if ((flags & SwCopyFlags::CopyAll) || aRg.aStart != aRg.aEnd)
         {
             if (pSttTextNd && bCopyCollFormat && pDestTextNd->HasSwAttrSet())
@@ -5077,7 +5077,7 @@ bool 
DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
         if ((flags & SwCopyFlags::CopyAll) || aRg.aStart != aRg.aEnd)
         {
             // Put the breaks back into the first node
-            if( aBrkSet.Count() && nullptr != ( pDestTextNd = pDoc->GetNodes()[
+            if( aBrkSet.Count() && nullptr != ( pDestTextNd = rDoc.GetNodes()[
                     pCopyPam->GetPoint()->nNode.GetIndex()+1 ]->GetTextNode()))
             {
                 pDestTextNd->SetAttr( aBrkSet );
@@ -5092,7 +5092,7 @@ bool 
DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
     // tdf#39400 and tdf#97526
     // when copy from document to ClipBoard, and it is from the first page
     //  and not the source has the page break
-    if (pDoc->IsClipBoard() && (rPam.GetPageNum(pStt == rPam.GetPoint()) == 1) 
&& !bCopyPageSource)
+    if (rDoc.IsClipBoard() && (rPam.GetPageNum(pStt == rPam.GetPoint()) == 1) 
&& !bCopyPageSource)
     {
         pDestTextNd->ResetAttr(RES_BREAK);        // remove the page-break
         pDestTextNd->ResetAttr(RES_PAGEDESC);
@@ -5151,7 +5151,7 @@ bool 
DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
     }
 
     // If Undo is enabled, store the inserted area
-    if (pDoc->GetIDocumentUndoRedo().DoesUndo())
+    if (rDoc.GetIDocumentUndoRedo().DoesUndo())
     {
         pUndo->SetInsertRange(*pCopyPam, true, nDeleteTextNodes);
     }
@@ -5168,12 +5168,12 @@ bool 
DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
         // #i86492# - use <SwDoc::SetNumRule(..)>, because it also handles the 
<ListId>
         // Don't reset indent attributes, that would mean loss of direct
         // formatting.
-        pDoc->SetNumRule( *pCopyPam, *pNumRuleToPropagate, false, nullptr,
+        rDoc.SetNumRule( *pCopyPam, *pNumRuleToPropagate, false, nullptr,
                           aListIdToPropagate, true, 
/*bResetIndentAttrs=*/false );
     }
 
-    pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld );
-    pDoc->getIDocumentState().SetModified();
+    rDoc.getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld );
+    rDoc.getIDocumentState().SetModified();
 
     return true;
 }
diff --git a/sw/source/core/doc/dbgoutsw.cxx b/sw/source/core/doc/dbgoutsw.cxx
index 3fb9c460bbd3..05a8e0b2d810 100644
--- a/sw/source/core/doc/dbgoutsw.cxx
+++ b/sw/source/core/doc/dbgoutsw.cxx
@@ -416,29 +416,26 @@ static OUString lcl_AnchoredFrames(const SwNode & rNode)
 {
     OUStringBuffer aResult("[");
 
-    const SwDoc * pDoc = rNode.GetDoc();
-    if (pDoc)
-    {
-        const SwFrameFormats * pFrameFormats = pDoc->GetSpzFrameFormats();
+    const SwDoc& rDoc = rNode.GetDoc();
+    const SwFrameFormats * pFrameFormats = rDoc.GetSpzFrameFormats();
 
-        if (pFrameFormats)
+    if (pFrameFormats)
+    {
+        bool bFirst = true;
+        for (SwFrameFormats::const_iterator i(pFrameFormats->begin());
+             i != pFrameFormats->end(); ++i)
         {
-            bool bFirst = true;
-            for (SwFrameFormats::const_iterator i(pFrameFormats->begin());
-                 i != pFrameFormats->end(); ++i)
+            const SwFormatAnchor & rAnchor = (*i)->GetAnchor();
+            const SwPosition * pPos = rAnchor.GetContentAnchor();
+
+            if (pPos && &pPos->nNode.GetNode() == &rNode)
             {
-                const SwFormatAnchor & rAnchor = (*i)->GetAnchor();
-                const SwPosition * pPos = rAnchor.GetContentAnchor();
-
-                if (pPos && &pPos->nNode.GetNode() == &rNode)
-                {
-                    if (! bFirst)
-                        aResult.append(", ");
-
-                    if (*i)
-                        aResult.append(lcl_dbg_out(**i));
-                    bFirst = false;
-                }
+                if (! bFirst)
+                    aResult.append(", ");
+
+                if (*i)
+                    aResult.append(lcl_dbg_out(**i));
+                bFirst = false;
             }
         }
     }
diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index 36ad4d6795ee..b9ab931ddc1b 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -1799,14 +1799,14 @@ void DelBookmarks(
     if(rStt.GetIndex() > rEnd.GetIndex()
         || (rStt == rEnd && (!pSttIdx || !pEndIdx || pSttIdx->GetIndex() >= 
pEndIdx->GetIndex())))
         return;
-    SwDoc* const pDoc = rStt.GetNode().GetDoc();
+    SwDoc& rDoc = rStt.GetNode().GetDoc();
 
-    pDoc->getIDocumentMarkAccess()->deleteMarks(rStt, rEnd, pSaveBkmk, 
pSttIdx, pEndIdx);
+    rDoc.getIDocumentMarkAccess()->deleteMarks(rStt, rEnd, pSaveBkmk, pSttIdx, 
pEndIdx);
 
     // Copy all Redlines which are in the move area into an array
     // which holds all position information as offset.
     // Assignment happens after moving.
-    SwRedlineTable& rTable = 
pDoc->getIDocumentRedlineAccess().GetRedlineTable();
+    SwRedlineTable& rTable = 
rDoc.getIDocumentRedlineAccess().GetRedlineTable();
     for(SwRangeRedline* pRedl : rTable)
     {
         // Is at position?
@@ -1823,7 +1823,7 @@ void DelBookmarks(
                 bool bStt = true;
                 SwContentNode* pCNd = pRStt->nNode.GetNode().GetContentNode();
                 if( !pCNd )
-                    pCNd = pDoc->GetNodes().GoNext( &pRStt->nNode );
+                    pCNd = rDoc.GetNodes().GoNext( &pRStt->nNode );
                 if (!pCNd)
                 {
                     bStt = false;
@@ -1853,7 +1853,7 @@ void DelBookmarks(
                 {
                     bStt = true;
                     pREnd->nNode = rEnd;
-                    pCNd = pDoc->GetNodes().GoNext( &pREnd->nNode );
+                    pCNd = rDoc.GetNodes().GoNext( &pREnd->nNode );
                     if( !pCNd )
                     {
                         pREnd->nNode = pRStt->nNode;
diff --git a/sw/source/core/doc/doccomp.cxx b/sw/source/core/doc/doccomp.cxx
index 149f2e1eb518..2b820d8d0500 100644
--- a/sw/source/core/doc/doccomp.cxx
+++ b/sw/source/core/doc/doccomp.cxx
@@ -1282,7 +1282,7 @@ bool SwCompareLine::ChangesInLine( const SwCompareLine& 
rLine,
     {
         SwTextNode& rDstNd = *const_cast<SwTextNode*>(m_rNode.GetTextNode());
         const SwTextNode& rSrcNd = *rLine.GetNode().GetTextNode();
-        SwDoc* pDstDoc = rDstNd.GetDoc();
+        SwDoc& rDstDoc = rDstNd.GetDoc();
 
         int nLcsLen = 0;
 
@@ -1376,14 +1376,14 @@ bool SwCompareLine::ChangesInLine( const SwCompareLine& 
rLine,
 
             if ( nSrcFrom < nSrcTo )
             {
-                bool bUndo = pDstDoc->GetIDocumentUndoRedo().DoesUndo();
-                pDstDoc->GetIDocumentUndoRedo().DoUndo( false );
+                bool bUndo = rDstDoc.GetIDocumentUndoRedo().DoesUndo();
+                rDstDoc.GetIDocumentUndoRedo().DoUndo( false );
                 SwPaM aCpyPam( rSrcNd, nSrcFrom );
                 aCpyPam.SetMark();
                 aCpyPam.GetPoint()->nContent = nSrcTo;
                 aCpyPam.GetDoc()->getIDocumentContentOperations().CopyRange( 
aCpyPam, *aPam.GetPoint(),
                     SwCopyFlags::CheckPosInFly);
-                pDstDoc->GetIDocumentUndoRedo().DoUndo( bUndo );
+                rDstDoc.GetIDocumentUndoRedo().DoUndo( bUndo );
 
                 SwPaM* pTmp = new SwPaM( *aPam.GetPoint(), rpDelRing.get() );
                 if( !rpDelRing )
diff --git a/sw/source/core/doc/doccorr.cxx b/sw/source/core/doc/doccorr.cxx
index 41f7b673d2fc..cdc0b5fe4145 100644
--- a/sw/source/core/doc/doccorr.cxx
+++ b/sw/source/core/doc/doccorr.cxx
@@ -88,8 +88,8 @@ void PaMCorrAbs( const SwPaM& rRange,
     SwPosition const aStart( *rRange.Start() );
     SwPosition const aEnd( *rRange.End() );
     SwPosition const aNewPos( rNewPos );
-    SwDoc *const pDoc = aStart.nNode.GetNode().GetDoc();
-    SwCursorShell *const pShell = pDoc->GetEditShell();
+    SwDoc& rDoc = aStart.nNode.GetNode().GetDoc();
+    SwCursorShell *const pShell = rDoc.GetEditShell();
 
     if( pShell )
     {
@@ -120,8 +120,8 @@ void PaMCorrAbs( const SwPaM& rRange,
         }
     }
 
-    pDoc->cleanupUnoCursorTable();
-    for(const auto& pWeakUnoCursor : pDoc->mvUnoCursorTable)
+    rDoc.cleanupUnoCursorTable();
+    for(const auto& pWeakUnoCursor : rDoc.mvUnoCursorTable)
     {
         auto pUnoCursor(pWeakUnoCursor.lock());
         if(!pUnoCursor)
@@ -243,11 +243,11 @@ void PaMCorrRel( const SwNodeIndex &rOldNode,
 {
     const SwNode* pOldNode = &rOldNode.GetNode();
     SwPosition aNewPos( rNewPos );
-    const SwDoc* pDoc = pOldNode->GetDoc();
+    const SwDoc& rDoc = pOldNode->GetDoc();
 
     const sal_Int32 nCntIdx = rNewPos.nContent.GetIndex() + nOffset;
 
-    SwCursorShell const* pShell = pDoc->GetEditShell();
+    SwCursorShell const* pShell = rDoc.GetEditShell();
     if( pShell )
     {
         for(const SwViewShell& rShell : pShell->GetRingContainer())
@@ -278,8 +278,8 @@ void PaMCorrRel( const SwNodeIndex &rOldNode,
        }
     }
 
-    pDoc->cleanupUnoCursorTable();
-    for(const auto& pWeakUnoCursor : pDoc->mvUnoCursorTable)
+    rDoc.cleanupUnoCursorTable();
+    for(const auto& pWeakUnoCursor : rDoc.mvUnoCursorTable)
     {
         auto pUnoCursor(pWeakUnoCursor.lock());
         if(!pUnoCursor)
diff --git a/sw/source/core/doc/docedt.cxx b/sw/source/core/doc/docedt.cxx
index 56b4d04718a9..70b09b5be20d 100644
--- a/sw/source/core/doc/docedt.cxx
+++ b/sw/source/core/doc/docedt.cxx
@@ -98,12 +98,12 @@ void RestFlyInRange( SaveFlyArr & rArr, const SwPosition& 
rStartPos,
         if (pCNd && 
pCNd->getLayoutFrame(pFormat->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout(),
 nullptr, nullptr))
             pFormat->MakeFrames();
     }
-    sw::CheckAnchoredFlyConsistency(*rStartPos.nNode.GetNode().GetDoc());
+    sw::CheckAnchoredFlyConsistency(rStartPos.nNode.GetNode().GetDoc());
 }
 
 void SaveFlyInRange( const SwNodeRange& rRg, SaveFlyArr& rArr )
 {
-    SwFrameFormats& rFormats = 
*rRg.aStart.GetNode().GetDoc()->GetSpzFrameFormats();
+    SwFrameFormats& rFormats = 
*rRg.aStart.GetNode().GetDoc().GetSpzFrameFormats();
     for( SwFrameFormats::size_type n = 0; n < rFormats.size(); ++n )
     {
         SwFrameFormat *const pFormat = rFormats[n];
@@ -128,13 +128,13 @@ void SaveFlyInRange( const SwNodeRange& rRg, SaveFlyArr& 
rArr )
             rFormats.erase( rFormats.begin() + n-- );
         }
     }
-    sw::CheckAnchoredFlyConsistency(*rRg.aStart.GetNode().GetDoc());
+    sw::CheckAnchoredFlyConsistency(rRg.aStart.GetNode().GetDoc());
 }
 
 void SaveFlyInRange( const SwPaM& rPam, const SwPosition& rInsPos,
                        SaveFlyArr& rArr, bool bMoveAllFlys )
 {
-    SwFrameFormats& rFormats = 
*rPam.GetPoint()->nNode.GetNode().GetDoc()->GetSpzFrameFormats();
+    SwFrameFormats& rFormats = 
*rPam.GetPoint()->nNode.GetNode().GetDoc().GetSpzFrameFormats();
     SwFrameFormat* pFormat;
     const SwFormatAnchor* pAnchor;
 
@@ -195,7 +195,7 @@ void SaveFlyInRange( const SwPaM& rPam, const SwPosition& 
rInsPos,
             }
         }
     }
-    
sw::CheckAnchoredFlyConsistency(*rPam.GetPoint()->nNode.GetNode().GetDoc());
+    sw::CheckAnchoredFlyConsistency(rPam.GetPoint()->nNode.GetNode().GetDoc());
 }
 
 /// Delete and move all Flys at the paragraph, that are within the selection.
@@ -214,8 +214,8 @@ void DelFlyInRange( const SwNodeIndex& rMkNdIdx,
     SwPosition const& rStart = mark <= point ? mark : point;
     SwPosition const& rEnd   = mark <= point ? point : mark;
 
-    SwDoc* pDoc = rMkNdIdx.GetNode().GetDoc();
-    SwFrameFormats& rTable = *pDoc->GetSpzFrameFormats();
+    SwDoc& rDoc = rMkNdIdx.GetNode().GetDoc();
+    SwFrameFormats& rTable = *rDoc.GetSpzFrameFormats();
     for ( auto i = rTable.size(); i; )
     {
         SwFrameFormat *pFormat = rTable[--i];
@@ -246,7 +246,7 @@ void DelFlyInRange( const SwNodeIndex& rMkNdIdx,
                     i = std::distance(rTable.begin(), rTable.find( pFormat ));
             }
 
-            pDoc->getIDocumentLayoutAccess().DelLayoutFormat( pFormat );
+            rDoc.getIDocumentLayoutAccess().DelLayoutFormat( pFormat );
 
             // DelLayoutFormat can also trigger the deletion of objects.
             if (i > rTable.size())
@@ -263,17 +263,17 @@ SaveRedlEndPosForRestore::SaveRedlEndPosForRestore( const 
SwNodeIndex& rInsIdx,
     : mnSaveContent( nCnt )
 {
     SwNode& rNd = rInsIdx.GetNode();
-    SwDoc* pDest = rNd.GetDoc();
-    if( pDest->getIDocumentRedlineAccess().GetRedlineTable().empty() )
+    SwDoc& rDest = rNd.GetDoc();
+    if( rDest.getIDocumentRedlineAccess().GetRedlineTable().empty() )
         return;
 
     SwRedlineTable::size_type nFndPos;
     const SwPosition* pEnd;
     SwPosition aSrcPos( rInsIdx, SwIndex( rNd.GetContentNode(), nCnt ));
-    pDest->getIDocumentRedlineAccess().GetRedline( aSrcPos, &nFndPos );
+    rDest.getIDocumentRedlineAccess().GetRedline( aSrcPos, &nFndPos );
     const SwRangeRedline* pRedl;
     while( nFndPos--
-          && *( pEnd = ( pRedl = 
pDest->getIDocumentRedlineAccess().GetRedlineTable()[ nFndPos ] )->End() ) == 
aSrcPos
+          && *( pEnd = ( pRedl = 
rDest.getIDocumentRedlineAccess().GetRedlineTable()[ nFndPos ] )->End() ) == 
aSrcPos
           && *pRedl->Start() < aSrcPos )
     {
         if( !mpSaveIndex )
@@ -783,7 +783,7 @@ static bool lcl_HyphenateNode( const SwNodePtr& rpNd, void* 
pArgs )
     {
         // sw_redlinehide: this will be called once per node for merged nodes;
         // the fully deleted ones won't have frames so are skipped.
-        SwContentFrame* pContentFrame = pNode->getLayoutFrame( 
pNode->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout() );
+        SwContentFrame* pContentFrame = pNode->getLayoutFrame( 
pNode->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout() );
         if( pContentFrame && 
!static_cast<SwTextFrame*>(pContentFrame)->IsHiddenNow() )
         {
             sal_uInt16 *pPageSt = pHyphArgs->GetPageSt();
@@ -799,7 +799,7 @@ static bool lcl_HyphenateNode( const SwNodePtr& rpNd, void* 
pArgs )
                 }
                 long nStat = nPageNr >= *pPageSt ? nPageNr - *pPageSt + 1
                                          : nPageNr + *pPageCnt - *pPageSt + 1;
-                ::SetProgressState( nStat, pNode->GetDoc()->GetDocShell() );
+                ::SetProgressState( nStat, pNode->GetDoc().GetDocShell() );
             }
             pHyphArgs->SetRange( rpNd );
             if( pNode->Hyphenate( *pHyphArgs ) )
diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx
index 1340aa1444b8..7b9e4847da5f 100644
--- a/sw/source/core/doc/docfld.cxx
+++ b/sw/source/core/doc/docfld.cxx
@@ -990,7 +990,7 @@ void SwDocUpdateField::MakeFieldList_( SwDoc& rDoc, int 
eGetMode )
 void SwDocUpdateField::GetBodyNode( const SwTextField& rTField, SwFieldIds 
nFieldWhich )
 {
     const SwTextNode& rTextNd = rTField.GetTextNode();
-    const SwDoc& rDoc = *rTextNd.GetDoc();
+    const SwDoc& rDoc = rTextNd.GetDoc();
 
     // always the first! (in tab headline, header-/footer)
     Point aPt;
@@ -1042,7 +1042,7 @@ void SwDocUpdateField::GetBodyNode( const SwTextField& 
rTField, SwFieldIds nFiel
 
 void SwDocUpdateField::GetBodyNode( const SwSectionNode& rSectNd )
 {
-    const SwDoc& rDoc = *rSectNd.GetDoc();
+    const SwDoc& rDoc = rSectNd.GetDoc();
     std::unique_ptr<SetGetExpField> pNew;
 
     if( rSectNd.GetIndex() < rDoc.GetNodes().GetEndOfExtras().GetIndex() )
diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx
index 90fa2ed9e289..dbafd42f1856 100644
--- a/sw/source/core/doc/docfmt.cxx
+++ b/sw/source/core/doc/docfmt.cxx
@@ -105,12 +105,12 @@ static bool lcl_RstAttr( const SwNodePtr& rpNd, void* 
pArgs )
         const bool bLocked = pNode->IsModifyLocked();
         pNode->LockModify();
 
-        SwDoc* pDoc = pNode->GetDoc();
+        SwDoc& rDoc = pNode->GetDoc();
 
         // remove unused attribute RES_LR_SPACE
         // add list attributes
         SfxItemSet aSavedAttrsSet(
-            pDoc->GetAttrPool(),
+            rDoc.GetAttrPool(),
             svl::Items<
                 RES_PARATR_NUMRULE, RES_PARATR_NUMRULE,
                 RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END - 1,
@@ -120,7 +120,7 @@ static bool lcl_RstAttr( const SwNodePtr& rpNd, void* pArgs 
)
         std::vector<sal_uInt16> aClearWhichIds;
         // restoring all paragraph list attributes
         {
-            SfxItemSet aListAttrSet( pDoc->GetAttrPool(), 
svl::Items<RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END - 1>{} );
+            SfxItemSet aListAttrSet( rDoc.GetAttrPool(), 
svl::Items<RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END - 1>{} );
             aListAttrSet.Set(*pAttrSetOfNode);
             if ( aListAttrSet.Count() )
             {
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index 45e432af4e84..38b997d6c9ca 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -799,10 +799,10 @@ void SwDoc::WriteLayoutCache( SvStream& rStream )
 
 IGrammarContact* getGrammarContact( const SwTextNode& rTextNode )
 {
-    const SwDoc* pDoc = rTextNode.GetDoc();
-    if( !pDoc || pDoc->IsInDtor() )
+    const SwDoc& rDoc = rTextNode.GetDoc();
+    if (rDoc.IsInDtor())
         return nullptr;
-    return pDoc->getGrammarContact();
+    return rDoc.getGrammarContact();
 }
 
 ::sfx2::IXmlIdRegistry&
diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx
index 2b1e63c995b3..8735715e6014 100644
--- a/sw/source/core/doc/doctxm.cxx
+++ b/sw/source/core/doc/doctxm.cxx
@@ -732,7 +732,7 @@ static const SwTextNode* lcl_FindChapterNode( const SwNode& 
rNd,
         if( pFrame )
         {
             SwPosition aPos( *pNd );
-            pNd = GetBodyTextNode( *pNd->GetDoc(), aPos, *pFrame );
+            pNd = GetBodyTextNode( pNd->GetDoc(), aPos, *pFrame );
             OSL_ENSURE( pNd, "Where's the paragraph?" );
         }
     }
@@ -759,7 +759,7 @@ bool SwTOXBaseSection::SetPosAtStartEnd( SwPosition& rPos ) 
const
     if( pSectNd )
     {
         rPos.nNode = *pSectNd;
-        SwContentNode* pCNd = pSectNd->GetDoc()->GetNodes().GoNext( 
&rPos.nNode );
+        SwContentNode* pCNd = pSectNd->GetDoc().GetNodes().GoNext( &rPos.nNode 
);
         rPos.nContent.Assign( pCNd, 0 );
         bRet = true;
     }
@@ -787,12 +787,10 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
         maMSTOCExpression.clear();
     }
 
-    SwDoc* pDoc = const_cast<SwDoc*>(pSectNd->GetDoc());
-
-    assert(pDoc); //Where is the document?
+    SwDoc& rDoc = const_cast<SwDoc&>(pSectNd->GetDoc());
 
     if (pAttr && GetFormat())
-        pDoc->ChgFormat(*GetFormat(), *pAttr);
+        rDoc.ChgFormat(*GetFormat(), *pAttr);
 
     // determine default page description, which will be used by the content 
nodes,
     // if no appropriate one is found.
@@ -842,11 +840,11 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
         if ( !pDefaultPageDesc )
         {
             // determine default page description
-            pDefaultPageDesc = &pDoc->GetPageDesc( 0 );
+            pDefaultPageDesc = &rDoc.GetPageDesc( 0 );
         }
     }
 
-    pDoc->getIDocumentState().SetModified();
+    rDoc.getIDocumentState().SetModified();
 
     // get current Language
     SwTOXInternational aIntl(  GetLanguage(),
@@ -866,7 +864,7 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
     const_cast<SwSectionNode*>(pSectNd)->DelFrames();
 
     // This would be a good time to update the Numbering
-    pDoc->UpdateNumRule();
+    rDoc.UpdateNumRule();
 
     if( GetCreateType() & SwTOXElement::Mark )
         UpdateMarks( aIntl, pOwnChapterNode, pLayout );
@@ -910,37 +908,37 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
 
     SwUndoUpdateIndex * pUndo(nullptr);
     {
-        pDoc->getIDocumentRedlineAccess().DeleteRedline( *pSectNd, true, 
RedlineType::Any );
+        rDoc.getIDocumentRedlineAccess().DeleteRedline( *pSectNd, true, 
RedlineType::Any );
 
         SwNodeIndex aSttIdx( *pSectNd, +1 );
         SwNodeIndex aEndIdx( *pSectNd->EndOfSectionNode() );
-        pFirstEmptyNd = pDoc->GetNodes().MakeTextNode( aEndIdx,
-                        
pDoc->getIDocumentStylePoolAccess().GetTextCollFromPool( RES_POOLCOLL_TEXT ) );
+        pFirstEmptyNd = rDoc.GetNodes().MakeTextNode( aEndIdx,
+                        
rDoc.getIDocumentStylePoolAccess().GetTextCollFromPool( RES_POOLCOLL_TEXT ) );
 
         {
             // Task 70995 - save and restore PageDesc and Break Attributes
             SwNodeIndex aNxtIdx( aSttIdx );
             const SwContentNode* pCNd = aNxtIdx.GetNode().GetContentNode();
             if( !pCNd )
-                pCNd = pDoc->GetNodes().GoNext( &aNxtIdx );
+                pCNd = rDoc.GetNodes().GoNext( &aNxtIdx );
             assert(pCNd != pFirstEmptyNd);
             assert(pCNd->GetIndex() < pFirstEmptyNd->GetIndex());
             if( pCNd->HasSwAttrSet() )
             {
-                SfxItemSet aBrkSet( pDoc->GetAttrPool(), aBreakSetRange );
+                SfxItemSet aBrkSet( rDoc.GetAttrPool(), aBreakSetRange );
                 aBrkSet.Put( *pCNd->GetpSwAttrSet() );
                 if( aBrkSet.Count() )
                     pFirstEmptyNd->SetAttr( aBrkSet );
             }
         }
 
-        if (pDoc->GetIDocumentUndoRedo().DoesUndo())
+        if (rDoc.GetIDocumentUndoRedo().DoesUndo())
         {
             // note: this will first append a SwUndoDelSection from the ctor...
             pUndo = new SwUndoUpdateIndex(*this);
             // tdf#123313 insert Undo *after* all CrossRefBookmark Undos have
             // been inserted by the Update*() functions
-            
pDoc->GetIDocumentUndoRedo().AppendUndo(std::unique_ptr<SwUndoUpdateIndex>(pUndo));
+            
rDoc.GetIDocumentUndoRedo().AppendUndo(std::unique_ptr<SwUndoUpdateIndex>(pUndo));
         }
         else
         {
@@ -953,7 +951,7 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
             // (flys must be deleted because the anchor nodes are removed)
             DelFlyInRange( SwNodeIndex(aSttIdx, -1), aEndIdx );
 
-            pDoc->GetNodes().Delete( aSttIdx, aEndIdx.GetIndex() - 
aSttIdx.GetIndex() );
+            rDoc.GetNodes().Delete( aSttIdx, aEndIdx.GetIndex() - 
aSttIdx.GetIndex() );
         }
     }
 
@@ -963,15 +961,15 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
         // then insert the headline section
         SwNodeIndex aIdx( *pSectNd, +1 );
 
-        SwTextNode* pHeadNd = pDoc->GetNodes().MakeTextNode( aIdx,
+        SwTextNode* pHeadNd = rDoc.GetNodes().MakeTextNode( aIdx,
                                 GetTextFormatColl( FORM_TITLE ) );
         pHeadNd->InsertText( GetTitle(), SwIndex( pHeadNd ) );
 
         SwSectionData headerData( SectionType::ToxHeader, GetTOXName()+"_Head" 
);
 
         SwNodeIndex aStt( *pHeadNd ); --aIdx;
-        SwSectionFormat* pSectFormat = pDoc->MakeSectionFormat();
-        pDoc->GetNodes().InsertTextSection(
+        SwSectionFormat* pSectFormat = rDoc.MakeSectionFormat();
+        rDoc.GetNodes().InsertTextSection(
                 aStt, *pSectFormat, headerData, nullptr, &aIdx, true, false);
 
         if (pUndo)
@@ -985,7 +983,7 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
     SwNodeIndex aInsPos( *pFirstEmptyNd, 1 );
     for( size_t nCnt = 0; nCnt < m_aSortArr.size(); ++nCnt )
     {
-        ::SetProgressState( 0, pDoc->GetDocShell() );
+        ::SetProgressState( 0, rDoc.GetDocShell() );
 
         // Put the Text into the TOC
         sal_uInt16 nLvl = m_aSortArr[ nCnt ]->GetLevel();
@@ -997,7 +995,7 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
         }
 
         // Generate: Set dynamic TabStops
-        SwTextNode* pTOXNd = pDoc->GetNodes().MakeTextNode( aInsPos , pColl );
+        SwTextNode* pTOXNd = rDoc.GetNodes().MakeTextNode( aInsPos , pColl );
         m_aSortArr[ nCnt ]->pTOXNd = pTOXNd;
 
         // Generate: Evaluate Form and insert the place holder for the
@@ -1025,12 +1023,12 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
         }
         // pass node index of table-of-content section and default page 
description
         // to method <GenerateText(..)>.
-        ::SetProgressState( 0, pDoc->GetDocShell() );
+        ::SetProgressState( 0, rDoc.GetDocShell() );
 
         std::shared_ptr<sw::ToxTabStopTokenHandler> tabStopTokenHandler =
                 std::make_shared<sw::DefaultToxTabStopTokenHandler>(
                         pSectNd->GetIndex(), *pDefaultPageDesc, 
GetTOXForm().IsRelTabPos(),
-                        
pDoc->GetDocumentSettingManager().get(DocumentSettingId::TABS_RELATIVE_TO_INDENT)
 ?
+                        
rDoc.GetDocumentSettingManager().get(DocumentSettingId::TABS_RELATIVE_TO_INDENT)
 ?
                                 
sw::DefaultToxTabStopTokenHandler::TABSTOPS_RELATIVE_TO_INDENT :
                                 
sw::DefaultToxTabStopTokenHandler::TABSTOPS_RELATIVE_TO_PAGE);
         sw::ToxTextGenerator ttgn(GetTOXForm(), tabStopTokenHandler);
@@ -1055,7 +1053,7 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
                 aEndIdx = *pSectNd;
             else
                 aEndIdx = *pFirstEmptyNd;
-            SwContentNode* pCNd = pDoc->GetNodes().GoNext( &aEndIdx );
+            SwContentNode* pCNd = rDoc.GetNodes().GoNext( &aEndIdx );
             if( pCNd ) // Robust against defect documents, e.g. i60336
                 pCNd->SetAttr( *pFirstEmptyNd->GetpSwAttrSet() );
         }
@@ -1065,10 +1063,10 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
     sal_uLong nIdx = pSectNd->GetIndex();
     // don't delete if index is empty
     if(nIdx + 2 < pSectNd->EndOfSectionIndex())
-        pDoc->GetNodes().Delete( aInsPos );
+        rDoc.GetNodes().Delete( aInsPos );
 
-    aN2L.RestoreUpperFrames( pDoc->GetNodes(), nIdx, nIdx + 1 );
-    o3tl::sorted_vector<SwRootFrame*> aAllLayouts = pDoc->GetAllLayouts();
+    aN2L.RestoreUpperFrames( rDoc.GetNodes(), nIdx, nIdx + 1 );
+    o3tl::sorted_vector<SwRootFrame*> aAllLayouts = rDoc.GetAllLayouts();
     for ( const auto& rpLayout : aAllLayouts )
     {
         SwFrame::CheckPageDescs( static_cast<SwPageFrame*>(rpLayout->Lower()) 
);
@@ -1849,15 +1847,15 @@ void SwTOXBaseSection::UpdatePageNum_( SwTextNode* pNd,
         xCharStyleIdx->push_back(aNumStr.getLength());
 
     // search by name
-    SwDoc* pDoc = pNd->GetDoc();
+    SwDoc& rDoc = pNd->GetDoc();
     sal_uInt16 nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( 
GetMainEntryCharStyle(), SwGetPoolIdFromName::ChrFmt );
     SwCharFormat* pCharFormat = nullptr;
     if(USHRT_MAX != nPoolId)
-        pCharFormat = 
pDoc->getIDocumentStylePoolAccess().GetCharFormatFromPool(nPoolId);
+        pCharFormat = 
rDoc.getIDocumentStylePoolAccess().GetCharFormatFromPool(nPoolId);
     else
-        pCharFormat = pDoc->FindCharFormatByName( GetMainEntryCharStyle() );
+        pCharFormat = rDoc.FindCharFormatByName( GetMainEntryCharStyle() );
     if(!pCharFormat)
-        pCharFormat = pDoc->MakeCharFormat(GetMainEntryCharStyle(), nullptr);
+        pCharFormat = rDoc.MakeCharFormat(GetMainEntryCharStyle(), nullptr);
 
     // find the page numbers in aNumStr and set the character style
     sal_Int32 nOffset = pNd->GetText().getLength() - aNumStr.getLength();
@@ -2021,7 +2019,7 @@ bool SwTOXBase::IsTOXBaseInReadonly() const
     if (!pSectNode)
         return false;
 
-    const SwDocShell* pDocSh = pSectNode->GetDoc()->GetDocShell();
+    const SwDocShell* pDocSh = pSectNode->GetDoc().GetDocShell();
     if (!pDocSh)
         return false;
 
diff --git a/sw/source/core/doc/ftnidx.cxx b/sw/source/core/doc/ftnidx.cxx
index 07250b97efe2..ce09a4cba229 100644
--- a/sw/source/core/doc/ftnidx.cxx
+++ b/sw/source/core/doc/ftnidx.cxx
@@ -63,21 +63,21 @@ void SwFootnoteIdxs::UpdateFootnote( const SwNodeIndex& 
rStt )
         return;
 
     // Get the NodesArray using the first foot note's StartIndex
-    SwDoc* pDoc = rStt.GetNode().GetDoc();
-    if( pDoc->IsInReading() )
+    SwDoc& rDoc = rStt.GetNode().GetDoc();
+    if( rDoc.IsInReading() )
         return ;
     SwTextFootnote* pTextFootnote;
 
-    const SwEndNoteInfo& rEndInfo = pDoc->GetEndNoteInfo();
-    const SwFootnoteInfo& rFootnoteInfo = pDoc->GetFootnoteInfo();
-    IDocumentRedlineAccess const& rIDRA(pDoc->getIDocumentRedlineAccess());
+    const SwEndNoteInfo& rEndInfo = rDoc.GetEndNoteInfo();
+    const SwFootnoteInfo& rFootnoteInfo = rDoc.GetFootnoteInfo();
+    IDocumentRedlineAccess const& rIDRA(rDoc.getIDocumentRedlineAccess());
 
     // For normal foot notes we treat per-chapter and per-document numbering
     // separately. For Endnotes we only have per-document numbering.
     if( FTNNUM_CHAPTER == rFootnoteInfo.m_eNum )
     {
         SwRootFrame const* pLayout(nullptr);
-        o3tl::sorted_vector<SwRootFrame*> layouts = pDoc->GetAllLayouts();
+        o3tl::sorted_vector<SwRootFrame*> layouts = rDoc.GetAllLayouts();
         // sw_redlinehide: here we need to know if there's *any* layout with
         // IsHideRedlines(), because then the hidden-numbers have to be updated
         for (SwRootFrame const* pTmp : layouts)
@@ -88,10 +88,10 @@ void SwFootnoteIdxs::UpdateFootnote( const SwNodeIndex& 
rStt )
             }
         }
 
-        const SwOutlineNodes& rOutlNds = pDoc->GetNodes().GetOutLineNds();
-        const SwNode *pChapterStartHidden(&pDoc->GetNodes().GetEndOfExtras());
+        const SwOutlineNodes& rOutlNds = rDoc.GetNodes().GetOutLineNds();
+        const SwNode *pChapterStartHidden(&rDoc.GetNodes().GetEndOfExtras());
         sal_uLong nChapterStart(pChapterStartHidden->GetIndex());
-        sal_uLong nChapterEnd(pDoc->GetNodes().GetEndOfContent().GetIndex());
+        sal_uLong nChapterEnd(rDoc.GetNodes().GetEndOfContent().GetIndex());
         sal_uLong nChapterEndHidden(nChapterEnd);
         if( !rOutlNds.empty() )
         {
@@ -270,16 +270,16 @@ void SwFootnoteIdxs::UpdateAllFootnote()
         return;
 
     // Get the NodesArray via the StartIndex of the first Footnote
-    SwDoc* pDoc = const_cast<SwDoc*>((*this)[ 0 ]->GetTextNode().GetDoc());
+    SwDoc& rDoc = const_cast<SwDoc&>((*this)[ 0 ]->GetTextNode().GetDoc());
     SwTextFootnote* pTextFootnote;
-    const SwEndNoteInfo& rEndInfo = pDoc->GetEndNoteInfo();
-    const SwFootnoteInfo& rFootnoteInfo = pDoc->GetFootnoteInfo();
-    IDocumentRedlineAccess const& rIDRA(pDoc->getIDocumentRedlineAccess());
+    const SwEndNoteInfo& rEndInfo = rDoc.GetEndNoteInfo();
+    const SwFootnoteInfo& rFootnoteInfo = rDoc.GetFootnoteInfo();
+    IDocumentRedlineAccess const& rIDRA(rDoc.getIDocumentRedlineAccess());
 
     SwUpdFootnoteEndNtAtEnd aNumArr;
 
-    SwRootFrame const* pLayout = 
pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
-    o3tl::sorted_vector<SwRootFrame*> aAllLayouts = pDoc->GetAllLayouts();
+    SwRootFrame const* pLayout = 
rDoc.getIDocumentLayoutAccess().GetCurrentLayout();
+    o3tl::sorted_vector<SwRootFrame*> aAllLayouts = rDoc.GetAllLayouts();
     // For normal Footnotes per-chapter and per-document numbering are treated 
separately.
     // For Endnotes we only have document-wise numbering.
     if( FTNNUM_CHAPTER == rFootnoteInfo.m_eNum )
@@ -294,7 +294,7 @@ void SwFootnoteIdxs::UpdateAllFootnote()
             }
         }
 
-        const SwOutlineNodes& rOutlNds = pDoc->GetNodes().GetOutLineNds();
+        const SwOutlineNodes& rOutlNds = rDoc.GetNodes().GetOutLineNds();
         sal_uInt16 nNo = 1;     // Number for the Footnotes
         sal_uInt16 nNoNo = 1;
         size_t nFootnoteIdx = 0;     // Index into theFootnoteIdx array
diff --git a/sw/source/core/doc/htmltbl.cxx b/sw/source/core/doc/htmltbl.cxx
index 8022218db3db..3851e061a2c7 100644
--- a/sw/source/core/doc/htmltbl.cxx
+++ b/sw/source/core/doc/htmltbl.cxx
@@ -483,11 +483,11 @@ void SwHTMLTableLayout::AutoLayoutPass1()
                     const SwStartNode *pSttNd = pCnts->GetStartNode();
                     if( pSttNd )
                     {
-                        const SwDoc *pDoc = pSttNd->GetDoc();
+                        const SwDoc& rDoc = pSttNd->GetDoc();
                         sal_uLong nIdx = pSttNd->GetIndex();
-                        while( !(pDoc->GetNodes()[nIdx])->IsEndNode() )
+                        while (!rDoc.GetNodes()[nIdx]->IsEndNode())
                         {
-                            SwTextNode *pTextNd = 
(pDoc->GetNodes()[nIdx])->GetTextNode();
+                            SwTextNode *pTextNd = 
(rDoc.GetNodes()[nIdx])->GetTextNode();
                             if( pTextNd )
                             {
                                 sal_uLong nMinNoAlignCnts = 0;
@@ -509,7 +509,7 @@ void SwHTMLTableLayout::AutoLayoutPass1()
                             }
                             else
                             {
-                                SwTableNode *pTabNd = 
(pDoc->GetNodes()[nIdx])->GetTableNode();
+                                SwTableNode *pTabNd = 
(rDoc.GetNodes()[nIdx])->GetTableNode();
                                 if( pTabNd )
                                 {
                                     SwHTMLTableLayout *pChild = 
pTabNd->GetTable().GetHTMLTableLayout();
diff --git a/sw/source/core/doc/notxtfrm.cxx b/sw/source/core/doc/notxtfrm.cxx
index cebb9b25d6e2..dd6058d6622c 100644
--- a/sw/source/core/doc/notxtfrm.cxx
+++ b/sw/source/core/doc/notxtfrm.cxx
@@ -774,7 +774,7 @@ void SwNoTextFrame::Modify( const SfxPoolItem* pOld, const 
SfxPoolItem* pNew )
                         if ( GetNode()->GetNodeType() == SwNodeType::Grf )
                         {
                             SwGrfNode* pNd = static_cast<SwGrfNode*>( 
GetNode());
-                            SwViewShell *pVSh = 
pNd->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+                            SwViewShell *pVSh = 
pNd->GetDoc().getIDocumentLayoutAccess().GetCurrentViewShell();
 
                             if(pVSh)
                             {
@@ -818,7 +818,7 @@ void SwNoTextFrame::Modify( const SfxPoolItem* pOld, const 
SfxPoolItem* pNew )
 
             SwRect aRect( getFrameArea() );
 
-            SwViewShell *pVSh = 
pNd->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+            SwViewShell *pVSh = 
pNd->GetDoc().getIDocumentLayoutAccess().GetCurrentViewShell();
             if( !pVSh )
                 break;
 
diff --git a/sw/source/core/doc/number.cxx b/sw/source/core/doc/number.cxx
index 32afd8828b7a..a565e22ce1fd 100644
--- a/sw/source/core/doc/number.cxx
+++ b/sw/source/core/doc/number.cxx
@@ -913,7 +913,7 @@ void SwNumRule::SetInvalidRule(bool bFlag)
         for ( const SwTextNode* pTextNode : maTextNodeList )
         {
             // #i111681# - applying patch from cmc
-            SwList* pList = 
pTextNode->GetDoc()->getIDocumentListsAccess().getListByName( 
pTextNode->GetListId() );
+            SwList* pList = 
pTextNode->GetDoc().getIDocumentListsAccess().getListByName( 
pTextNode->GetListId() );
             OSL_ENSURE( pList, "<SwNumRule::SetInvalidRule(..)> - list at 
which the text node is registered at does not exist. This is a serious issue.");
             if ( pList )
             {
@@ -1024,7 +1024,7 @@ void SwNumRule::Validate()
     o3tl::sorted_vector< SwList* > aLists;
     for ( const SwTextNode* pTextNode : maTextNodeList )
     {
-        aLists.insert( 
pTextNode->GetDoc()->getIDocumentListsAccess().getListByName( 
pTextNode->GetListId() ) );
+        aLists.insert( 
pTextNode->GetDoc().getIDocumentListsAccess().getListByName( 
pTextNode->GetListId() ) );
     }
     for ( auto aList : aLists )
         aList->ValidateListTree();
diff --git a/sw/source/core/doc/rdfhelper.cxx b/sw/source/core/doc/rdfhelper.cxx
index d404b477e8af..651a899ff157 100644
--- a/sw/source/core/doc/rdfhelper.cxx
+++ b/sw/source/core/doc/rdfhelper.cxx
@@ -201,28 +201,28 @@ void SwRDFHelper::cloneStatements(const 
css::uno::Reference<css::frame::XModel>&
 
 std::map<OUString, OUString> SwRDFHelper::getTextNodeStatements(const 
OUString& rType, SwTextNode& rTextNode)
 {
-    uno::Reference<rdf::XResource> 
xTextNode(SwXParagraph::CreateXParagraph(*rTextNode.GetDoc(), &rTextNode), 
uno::UNO_QUERY);
-    return getStatements(rTextNode.GetDoc()->GetDocShell()->GetBaseModel(), 
rType, xTextNode);
+    uno::Reference<rdf::XResource> 
xTextNode(SwXParagraph::CreateXParagraph(rTextNode.GetDoc(), &rTextNode), 
uno::UNO_QUERY);
+    return getStatements(rTextNode.GetDoc().GetDocShell()->GetBaseModel(), 
rType, xTextNode);
 }
 
 void SwRDFHelper::addTextNodeStatement(const OUString& rType, const OUString& 
rPath, SwTextNode& rTextNode, const OUString& rKey, const OUString& rValue)
 {
-    uno::Reference<rdf::XResource> 
xSubject(SwXParagraph::CreateXParagraph(*rTextNode.GetDoc(), &rTextNode), 
uno::UNO_QUERY);
-    addStatement(rTextNode.GetDoc()->GetDocShell()->GetBaseModel(), rType, 
rPath, xSubject, rKey, rValue);
+    uno::Reference<rdf::XResource> 
xSubject(SwXParagraph::CreateXParagraph(rTextNode.GetDoc(), &rTextNode), 
uno::UNO_QUERY);
+    addStatement(rTextNode.GetDoc().GetDocShell()->GetBaseModel(), rType, 
rPath, xSubject, rKey, rValue);
 }
 
 void SwRDFHelper::removeTextNodeStatement(const OUString& rType, SwTextNode& 
rTextNode, const OUString& rKey, const OUString& rValue)
 {
     uno::Reference<uno::XComponentContext> 
xComponentContext(comphelper::getProcessComponentContext());
     uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, 
rType);
-    uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(rTextNode.GetDoc()->GetDocShell()->GetBaseModel(), 
uno::UNO_QUERY);
+    uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(rTextNode.GetDoc().GetDocShell()->GetBaseModel(), 
uno::UNO_QUERY);
     const uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = 
getGraphNames(xDocumentMetadataAccess, xType);
     if (!aGraphNames.hasElements())
         return;
 
     uno::Reference<rdf::XURI> xGraphName = aGraphNames[0];
     uno::Reference<rdf::XNamedGraph> xGraph = 
xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName);
-    uno::Reference<rdf::XResource> 
xSubject(SwXParagraph::CreateXParagraph(*rTextNode.GetDoc(), &rTextNode), 
uno::UNO_QUERY);
+    uno::Reference<rdf::XResource> 
xSubject(SwXParagraph::CreateXParagraph(rTextNode.GetDoc(), &rTextNode), 
uno::UNO_QUERY);
     uno::Reference<rdf::XURI> xKey = rdf::URI::create(xComponentContext, rKey);
     uno::Reference<rdf::XLiteral> xValue = 
rdf::Literal::create(xComponentContext, rValue);
     xGraph->removeStatements(xSubject, xKey, xValue);
@@ -232,7 +232,7 @@ void SwRDFHelper::updateTextNodeStatement(const OUString& 
rType, const OUString&
 {
     uno::Reference<uno::XComponentContext> 
xComponentContext(comphelper::getProcessComponentContext());
     uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, 
rType);
-    uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(rTextNode.GetDoc()->GetDocShell()->GetBaseModel(), 
uno::UNO_QUERY);
+    uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(rTextNode.GetDoc().GetDocShell()->GetBaseModel(), 
uno::UNO_QUERY);
     const uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = 
getGraphNames(xDocumentMetadataAccess, xType);
     uno::Reference<rdf::XURI> xGraphName;
     if (aGraphNames.hasElements())
@@ -246,7 +246,7 @@ void SwRDFHelper::updateTextNodeStatement(const OUString& 
rType, const OUString&
     }
 
     uno::Reference<rdf::XNamedGraph> xGraph = 
xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName);
-    uno::Reference<rdf::XResource> 
xSubject(SwXParagraph::CreateXParagraph(*rTextNode.GetDoc(), &rTextNode), 
uno::UNO_QUERY);
+    uno::Reference<rdf::XResource> 
xSubject(SwXParagraph::CreateXParagraph(rTextNode.GetDoc(), &rTextNode), 
uno::UNO_QUERY);
     uno::Reference<rdf::XURI> xKey = rdf::URI::create(xComponentContext, rKey);
 
     if (aGraphNames.hasElements())
diff --git a/sw/source/core/doc/tblrwcl.cxx b/sw/source/core/doc/tblrwcl.cxx
index 04142282bebb..c62bbf5b7a35 100644
--- a/sw/source/core/doc/tblrwcl.cxx
+++ b/sw/source/core/doc/tblrwcl.cxx
@@ -215,7 +215,7 @@ struct CpyPara
     bool bCpyContent;
 
     CpyPara( SwTableNode* pNd, sal_uInt16 nCopies, CpyTabFrames& rFrameArr )
-        : pDoc( pNd->GetDoc() ), pTableNd( pNd ), rTabFrameArr(rFrameArr),
+        : pDoc( &pNd->GetDoc() ), pTableNd( pNd ), rTabFrameArr(rFrameArr),
         pInsLine(nullptr), pInsBox(nullptr), nOldSize(0), nNewSize(0),
         nMinLeft(ULONG_MAX), nMaxRight(0),
         nCpyCnt(nCopies), nInsPos(0),
@@ -733,7 +733,7 @@ void DeleteBox_( SwTable& rTable, SwTableBox* pBox, SwUndo* 
pUndo,
             if( pUndo && pUndo->IsDelBox() )
                 static_cast<SwUndoTableNdsChg*>(pUndo)->SaveSection( pSttNd );
             else
-                
pSttNd->GetDoc()->getIDocumentContentOperations().DeleteSection( pSttNd );
+                
pSttNd->GetDoc().getIDocumentContentOperations().DeleteSection( pSttNd );
         }
 
         // Also delete the Line?
diff --git a/sw/source/core/docnode/ndcopy.cxx 
b/sw/source/core/docnode/ndcopy.cxx
index a4a907b4fc9a..152c8e20deb0 100644
--- a/sw/source/core/docnode/ndcopy.cxx
+++ b/sw/source/core/docnode/ndcopy.cxx
@@ -335,8 +335,8 @@ void SwTextNode::CopyCollFormat( SwTextNode& rDestNd )
 {
     // Copy the formats into the other document:
     // Special case for PageBreak/PageDesc/ColBrk
-    SwDoc* pDestDoc = rDestNd.GetDoc();
-    SwAttrSet aPgBrkSet( pDestDoc->GetAttrPool(), aBreakSetRange );
+    SwDoc& rDestDoc = rDestNd.GetDoc();
+    SwAttrSet aPgBrkSet( rDestDoc.GetAttrPool(), aBreakSetRange );
     const SwAttrSet* pSet;
 
     pSet = rDestNd.GetpSwAttrSet();
@@ -351,7 +351,7 @@ void SwTextNode::CopyCollFormat( SwTextNode& rDestNd )
             aPgBrkSet.Put( *pAttr );
     }
 
-    rDestNd.ChgFormatColl( pDestDoc->CopyTextColl( *GetTextColl() ));
+    rDestNd.ChgFormatColl( rDestDoc.CopyTextColl( *GetTextColl() ));
     pSet = GetpSwAttrSet();
     if( nullptr != pSet )
         pSet->CopyToModify( rDestNd );
diff --git a/sw/source/core/docnode/ndnotxt.cxx 
b/sw/source/core/docnode/ndnotxt.cxx
index 9029f9348827..3da7273bfc7c 100644
--- a/sw/source/core/docnode/ndnotxt.cxx
+++ b/sw/source/core/docnode/ndnotxt.cxx
@@ -66,7 +66,7 @@ void SwNoTextNode::NewAttrSet( SwAttrPool& rPool )
     aNewAttrSet.Put( aFormatColl );
 
     aNewAttrSet.SetParent( &GetFormatColl()->GetAttrSet() );
-    mpAttrSet = GetDoc()->GetIStyleAccess().getAutomaticStyle( aNewAttrSet, 
IStyleAccess::AUTO_STYLE_NOTXT );
+    mpAttrSet = GetDoc().GetIStyleAccess().getAutomaticStyle( aNewAttrSet, 
IStyleAccess::AUTO_STYLE_NOTXT );
 }
 
 /// Dummies for loading/saving of persistent data
diff --git a/sw/source/core/docnode/ndsect.cxx 
b/sw/source/core/docnode/ndsect.cxx
index a2fcd8b7eae1..54ec466d6165 100644
--- a/sw/source/core/docnode/ndsect.cxx
+++ b/sw/source/core/docnode/ndsect.cxx
@@ -750,7 +750,7 @@ void SwDoc::UpdateSection( size_t const nPos, SwSectionData 
& rNewData,
 
 void sw_DeleteFootnote( SwSectionNode *pNd, sal_uLong nStt, sal_uLong nEnd )
 {
-    SwFootnoteIdxs& rFootnoteArr = pNd->GetDoc()->GetFootnoteIdxs();
+    SwFootnoteIdxs& rFootnoteArr = pNd->GetDoc().GetFootnoteIdxs();
     if( rFootnoteArr.empty() )
         return;
 
@@ -1338,7 +1338,7 @@ void SwSectionNode::NodesArrChgd()
     // Moving Nodes to the UndoNodes array?
     if( rNds.IsDocNodes() )
     {
-        OSL_ENSURE( pDoc == GetDoc(),
+        OSL_ENSURE( pDoc == &GetDoc(),
                 "Moving to different Documents?" );
         if( m_pSection->IsLinkType() ) // Remove the Link
             m_pSection->CreateLink( 
pDoc->getIDocumentLayoutAccess().GetCurrentViewShell() ? 
LinkCreateType::Connect : LinkCreateType::NONE );
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index fb705fc72650..c9c3e4546b8d 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -1030,7 +1030,7 @@ SwTableNode* SwNodes::TextToTable( const SwNodeRange& 
rRange, sal_Unicode cCh,
             cCh = 0x09;
 
             // Get the separator's position from the first Node, in order for 
the Boxes to be set accordingly
-            SwTextFrameInfo aFInfo( 
static_cast<SwTextFrame*>(pTextNd->getLayoutFrame( 
pTextNd->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout() )) );
+            SwTextFrameInfo aFInfo( 
static_cast<SwTextFrame*>(pTextNd->getLayoutFrame( 
pTextNd->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout() )) );
             if( aFInfo.IsOneLine() ) // only makes sense in this case
             {
                 OUString const& rText(pTextNd->GetText());
@@ -2488,13 +2488,10 @@ void SwTableNode::SetNewTable( std::unique_ptr<SwTable> 
pNewTable, bool bNewFram
 
 void SwTableNode::RemoveRedlines()
 {
-    SwDoc* pDoc = GetDoc();
-    if (pDoc)
-    {
-        SwTable& rTable = GetTable();
-        if ( pDoc->getIDocumentRedlineAccess().HasExtraRedlineTable() )
-            
pDoc->getIDocumentRedlineAccess().GetExtraRedlineTable().DeleteAllTableRedlines(*pDoc,
 rTable, true, RedlineType::Any);
-    }
+    SwDoc& rDoc = GetDoc();
+    SwTable& rTable = GetTable();
+    if (rDoc.getIDocumentRedlineAccess().HasExtraRedlineTable())
+        
rDoc.getIDocumentRedlineAccess().GetExtraRedlineTable().DeleteAllTableRedlines(rDoc,
 rTable, true, RedlineType::Any);
 }
 
 void SwDoc::GetTabCols( SwTabCols &rFill, const SwCellFrame* pBoxFrame )
@@ -4215,7 +4212,7 @@ void SwDoc::ClearLineNumAttrs( SwPosition const & rPos )
         return;
 
     const SfxPoolItem* pFormatItem = nullptr;
-    SfxItemSet rSet( pTextNode->GetDoc()->GetAttrPool(),
+    SfxItemSet rSet( pTextNode->GetDoc().GetAttrPool(),
                 svl::Items<RES_PARATR_BEGIN, RES_PARATR_END - 1>{});
     pTextNode->SwContentNode::GetAttr( rSet );
     if ( SfxItemState::SET != rSet.GetItemState( RES_PARATR_NUMRULE , false , 
&pFormatItem ) )
@@ -4336,7 +4333,7 @@ bool SwDoc::InsCopyOfTable( SwPosition& rInsPos, const 
SwSelBoxes& rBoxes,
             GetIDocumentUndoRedo().DoUndo(false);
         }
 
-        rtl::Reference<SwDoc> xCpyDoc( 
const_cast<SwDoc*>(pSrcTableNd->GetDoc()) );
+        rtl::Reference<SwDoc> 
xCpyDoc(&const_cast<SwDoc&>(pSrcTableNd->GetDoc()));
         bool bDelCpyDoc = xCpyDoc == this;
 
         if( bDelCpyDoc )
diff --git a/sw/source/core/docnode/ndtbl1.cxx 
b/sw/source/core/docnode/ndtbl1.cxx
index faeaeafac5ba..486baf643c83 100644
--- a/sw/source/core/docnode/ndtbl1.cxx
+++ b/sw/source/core/docnode/ndtbl1.cxx
@@ -130,9 +130,9 @@ static void lcl_GetStartEndCell( const SwCursor& rCursor,
     SwContentNode* pMarkNd  = rCursor.GetContentNode(false);
 
     std::pair<Point, bool> tmp(aPtPos, true);
-    SwFrame *const pPointFrame = pPointNd ? 
pPointNd->getLayoutFrame(pPointNd->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout(),
 nullptr, &tmp) : nullptr;
+    SwFrame *const pPointFrame = pPointNd ? 
pPointNd->getLayoutFrame(pPointNd->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout(),
 nullptr, &tmp) : nullptr;
     tmp.first = aMkPos;
-    SwFrame *const pMarkFrame = pMarkNd ? 
pMarkNd->getLayoutFrame(pMarkNd->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout(),
 nullptr, &tmp) : nullptr;
+    SwFrame *const pMarkFrame = pMarkNd ? 
pMarkNd->getLayoutFrame(pMarkNd->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout(),
 nullptr, &tmp) : nullptr;
 
     prStart = pPointFrame ? pPointFrame->GetUpper() : nullptr;
     prEnd   = pMarkFrame  ? pMarkFrame->GetUpper() : nullptr;
@@ -820,7 +820,7 @@ void SwDoc::SetTabBorders( const SwCursor& rCursor, const 
SfxItemSet& rSet )
     SwHTMLTableLayout *pTableLayout = rTable.GetHTMLTableLayout();
     if( pTableLayout )
     {
-        SwContentFrame* pFrame = rCursor.GetContentNode()->getLayoutFrame( 
rCursor.GetContentNode()->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout()
 );
+        SwContentFrame* pFrame = rCursor.GetContentNode()->getLayoutFrame( 
rCursor.GetContentNode()->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout()
 );
         SwTabFrame* pTabFrame = pFrame->ImplFindTabFrame();
 
         pTableLayout->BordersChanged(
@@ -916,7 +916,7 @@ void SwDoc::SetTabLineStyle( const SwCursor& rCursor,
     SwHTMLTableLayout *pTableLayout = rTable.GetHTMLTableLayout();
     if( pTableLayout )
     {
-        SwContentFrame* pFrame = rCursor.GetContentNode()->getLayoutFrame( 
rCursor.GetContentNode()->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout()
 );
+        SwContentFrame* pFrame = rCursor.GetContentNode()->getLayoutFrame( 
rCursor.GetContentNode()->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout()
 );
         SwTabFrame* pTabFrame = pFrame->ImplFindTabFrame();
 
         pTableLayout->BordersChanged(
@@ -1183,7 +1183,7 @@ void SwDoc::SetBoxAttr( const SwCursor& rCursor, const 
SfxPoolItem &rNew )
     SwHTMLTableLayout *pTableLayout = rTable.GetHTMLTableLayout();
     if( pTableLayout )
     {
-        SwContentFrame* pFrame = rCursor.GetContentNode()->getLayoutFrame( 
rCursor.GetContentNode()->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout()
 );
+        SwContentFrame* pFrame = rCursor.GetContentNode()->getLayoutFrame( 
rCursor.GetContentNode()->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout()
 );
         SwTabFrame* pTabFrame = pFrame->ImplFindTabFrame();
 
         pTableLayout->Resize(
diff --git a/sw/source/core/docnode/node.cxx b/sw/source/core/docnode/node.cxx
index 2051fe72f0f4..0f352dc28e69 100644
--- a/sw/source/core/docnode/node.cxx
+++ b/sw/source/core/docnode/node.cxx
@@ -344,7 +344,7 @@ SwNode::SwNode( SwNodes& rNodes, sal_uLong nPos, const 
SwNodeType nNdType )
 
 SwNode::~SwNode()
 {
-    assert(!m_pAnchoredFlys || GetDoc()->IsInDtor()); // must all be deleted
+    assert(!m_pAnchoredFlys || GetDoc().IsInDtor()); // must all be deleted
 }
 
 /// Find the TableNode in which it is located.
@@ -380,7 +380,7 @@ bool SwNode::IsInVisibleArea( SwViewShell const * pSh ) 
const
 
     if( !pSh )
         // Get the Shell from the Doc
-        pSh = GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+        pSh = GetDoc().getIDocumentLayoutAccess().GetCurrentViewShell();
 
     if( pSh )
     {
@@ -429,7 +429,7 @@ bool SwNode::IsProtect() const
     if( nullptr != pSttNd )
     {
         SwContentFrame* pCFrame;
-        if( IsContentNode() && nullptr != (pCFrame = static_cast<const 
SwContentNode*>(this)->getLayoutFrame( 
GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout() ) ))
+        if( IsContentNode() && nullptr != (pCFrame = static_cast<const 
SwContentNode*>(this)->getLayoutFrame( 
GetDoc().getIDocumentLayoutAccess().GetCurrentLayout() ) ))
             return pCFrame->IsProtected();
 
         const SwTableBox* pBox = pSttNd->FindTableNode()->GetTable().
@@ -455,7 +455,7 @@ bool SwNode::IsProtect() const
     pSttNd = FindFootnoteStartNode();
     if( nullptr != pSttNd )
     {
-        const SwTextFootnote* pTFootnote = 
GetDoc()->GetFootnoteIdxs().SeekEntry(
+        const SwTextFootnote* pTFootnote = 
GetDoc().GetFootnoteIdxs().SeekEntry(
                                 SwNodeIndex( *pSttNd ) );
         if( pTFootnote )
             return pTFootnote->GetTextNode().IsProtect();
@@ -498,7 +498,7 @@ const SwPageDesc* SwNode::FindPageDesc( size_t* 
pPgDescNdIdx ) const
     {
         const SwFrame* pFrame;
         const SwPageFrame* pPage;
-        if (pNode && nullptr != (pFrame = 
pNode->getLayoutFrame(pNode->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout(),
 nullptr, nullptr)) &&
+        if (pNode && nullptr != (pFrame = 
pNode->getLayoutFrame(pNode->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout(),
 nullptr, nullptr)) &&
             nullptr != ( pPage = pFrame->FindPageFrame() ) )
         {
             pPgDesc = pPage->GetPageDesc();
@@ -512,7 +512,7 @@ const SwPageDesc* SwNode::FindPageDesc( size_t* 
pPgDescNdIdx ) const
     if( !pPgDesc )
     {
         // Thus via the nodes array
-        const SwDoc* pDoc = GetDoc();
+        const SwDoc& rDoc = GetDoc();
         const SwNode* pNd = this;
         const SwStartNode* pSttNd;
         if( pNd->GetIndex() < GetNodes().GetEndOfExtras().GetIndex() &&
@@ -520,7 +520,7 @@ const SwPageDesc* SwNode::FindPageDesc( size_t* 
pPgDescNdIdx ) const
         {
             // Find the right Anchor first
             const SwFrameFormat* pFormat = nullptr;
-            const SwFrameFormats& rFormats = *pDoc->GetSpzFrameFormats();
+            const SwFrameFormats& rFormats = *rDoc.GetSpzFrameFormats();
 
             for( size_t n = 0; n < rFormats.size(); ++n )
             {
@@ -587,7 +587,7 @@ const SwPageDesc* SwNode::FindPageDesc( size_t* 
pPgDescNdIdx ) const
         {
             if( pNd->GetIndex() > GetNodes().GetEndOfAutotext().GetIndex() )
             {
-                pPgDesc = &pDoc->GetPageDesc( 0 );
+                pPgDesc = &rDoc.GetPageDesc( 0 );
                 pNd = nullptr;
             }
             else
@@ -610,9 +610,9 @@ const SwPageDesc* SwNode::FindPageDesc( size_t* 
pPgDescNdIdx ) const
                         eAskUse = UseOnPage::FooterShare;
                     }
 
-                    for( size_t n = pDoc->GetPageDescCnt(); n && !pPgDesc; )
+                    for( size_t n = rDoc.GetPageDescCnt(); n && !pPgDesc; )
                     {
-                        const SwPageDesc& rPgDsc = pDoc->GetPageDesc( --n );
+                        const SwPageDesc& rPgDsc = rDoc.GetPageDesc( --n );
                         const SwFrameFormat* pFormat = &rPgDsc.GetMaster();
                         int nStt = 0, nLast = 1;
                         if( !( eAskUse & rPgDsc.ReadUseOn() )) ++nLast;
@@ -639,14 +639,14 @@ const SwPageDesc* SwNode::FindPageDesc( size_t* 
pPgDescNdIdx ) const
                     }
 
                     if( !pPgDesc )
-                        pPgDesc = &pDoc->GetPageDesc( 0 );
+                        pPgDesc = &rDoc.GetPageDesc( 0 );
                     pNd = nullptr;
                 }
                 else if( nullptr != ( pSttNd = pNd->FindFootnoteStartNode() ))
                 {
                     // the Anchor can only be in the Body text
                     const SwTextFootnote* pTextFootnote;
-                    const SwFootnoteIdxs& rFootnoteArr = 
pDoc->GetFootnoteIdxs();
+                    const SwFootnoteIdxs& rFootnoteArr = 
rDoc.GetFootnoteIdxs();
                     for( size_t n = 0; n < rFootnoteArr.size(); ++n )
                         if( nullptr != ( pTextFootnote = rFootnoteArr[ n 
])->GetStartNode() &&
                             static_cast<SwNode const *>(pSttNd) ==
@@ -663,7 +663,7 @@ const SwPageDesc* SwNode::FindPageDesc( size_t* 
pPgDescNdIdx ) const
                     OSL_ENSURE( pNd->FindFlyStartNode(),
                             "Where is this Node?" );
 
-                    pPgDesc = &pDoc->GetPageDesc( 0 );
+                    pPgDesc = &rDoc.GetPageDesc( 0 );
                     pNd = nullptr;

... etc. - the rest is truncated
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to