sw/inc/pam.hxx                               |    2 +-
 sw/source/core/crsr/pam.cxx                  |    4 ++--
 sw/source/core/doc/docfld.cxx                |    2 +-
 sw/source/core/doc/ftnidx.cxx                |    3 +--
 sw/source/core/layout/frmtool.cxx            |   13 ++++++-------
 sw/source/core/txtnode/modeltoviewhelper.cxx |    6 +++---
 sw/source/filter/ww8/wrtw8nds.cxx            |    2 +-
 sw/source/uibase/utlui/content.cxx           |    8 ++++----
 8 files changed, 19 insertions(+), 21 deletions(-)

New commits:
commit 3caade9b4734245471347c7eb20090607d70f7b7
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Mon Jul 25 12:34:54 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Jul 26 07:54:04 2022 +0200

    simplify some use of SwPosition
    
    by moving the const_cast inside the constructor
    
    Change-Id: I1b43a6d3759de250475f0ebc7d65449ff800b570
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137405
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/inc/pam.hxx b/sw/inc/pam.hxx
index 49b1aa582c4e..fad762cab0e8 100644
--- a/sw/inc/pam.hxx
+++ b/sw/inc/pam.hxx
@@ -41,7 +41,7 @@ struct SAL_WARN_UNUSED SW_DLLPUBLIC SwPosition
     SwPosition( const SwNodeIndex &rNode, const SwContentIndex &rContent );
     explicit SwPosition( const SwNodeIndex &rNode );
     explicit SwPosition( const SwNode& rNode );
-    explicit SwPosition( SwContentNode& rNode, const sal_Int32 nOffset = 0 );
+    explicit SwPosition( const SwContentNode& rNode, const sal_Int32 nOffset = 
0 );
 
     /**
        Returns the document this position is in.
diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx
index 7fc9d34258a5..0ba3705781bd 100644
--- a/sw/source/core/crsr/pam.cxx
+++ b/sw/source/core/crsr/pam.cxx
@@ -72,8 +72,8 @@ SwPosition::SwPosition( const SwNode& rNode )
 {
 }
 
-SwPosition::SwPosition( SwContentNode & rNode, const sal_Int32 nOffset )
-    : nNode( rNode ), nContent( &rNode, nOffset )
+SwPosition::SwPosition( const SwContentNode & rNode, const sal_Int32 nOffset )
+    : nNode( rNode ), nContent( const_cast<SwContentNode*>(&rNode), nOffset )
 {
 }
 
diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx
index 294be63631e4..b32e3e05e59d 100644
--- a/sw/source/core/doc/docfld.cxx
+++ b/sw/source/core/doc/docfld.cxx
@@ -1068,7 +1068,7 @@ void SwDocUpdateField::GetBodyNode( const SwTextField& 
rTField, SwFieldIds nFiel
     Point aPt;
     std::pair<Point, bool> const tmp(aPt, false);
     // need pos to get the frame on the correct page
-    SwPosition const pos(const_cast<SwTextNode&>(rTextNd), rTField.GetStart());
+    SwPosition const pos(rTextNd, rTField.GetStart());
     const SwFrame* pFrame = rTextNd.getLayoutFrame(
         rDoc.getIDocumentLayoutAccess().GetCurrentLayout(), &pos, &tmp);
 
diff --git a/sw/source/core/doc/ftnidx.cxx b/sw/source/core/doc/ftnidx.cxx
index 1c8a0bf6b1b6..778a6ed388ee 100644
--- a/sw/source/core/doc/ftnidx.cxx
+++ b/sw/source/core/doc/ftnidx.cxx
@@ -38,8 +38,7 @@ bool IsFootnoteDeleted(IDocumentRedlineAccess const& rIDRA,
         SwTextFootnote const& rTextFootnote)
 {
     SwRedlineTable::size_type tmp;
-    SwPosition const pos(const_cast<SwTextNode&>(rTextFootnote.GetTextNode()),
-            rTextFootnote.GetStart());
+    SwPosition const pos(rTextFootnote.GetTextNode(), 
rTextFootnote.GetStart());
     SwRangeRedline const*const pRedline(rIDRA.GetRedline(pos, &tmp));
     return (pRedline
         && pRedline->GetType() == RedlineType::Delete
diff --git a/sw/source/core/layout/frmtool.cxx 
b/sw/source/core/layout/frmtool.cxx
index ee50dcc7cd12..f221a9b7d812 100644
--- a/sw/source/core/layout/frmtool.cxx
+++ b/sw/source/core/layout/frmtool.cxx
@@ -1112,8 +1112,8 @@ static bool IsShown(SwNodeOffset const nIndex,
         return pIter == nullptr // not merged
             || pIter != pEnd    // at least one char visible in node
             || !IsSelectFrameAnchoredAtPara(rAnchor,
-                    SwPosition(const_cast<SwTextNode&>(*pFirstNode), 0),
-                    SwPosition(const_cast<SwTextNode&>(*pLastNode), 
pLastNode->Len()));
+                    SwPosition(*pFirstNode, 0),
+                    SwPosition(*pLastNode, pLastNode->Len()));
     }
     if (pIter)
     {
@@ -1153,10 +1153,9 @@ static bool IsShown(SwNodeOffset const nIndex,
                     else
                     {
                         SwPosition const start(
-                            const_cast<SwTextNode&>(
-                                iter == *pIter
-                                    ? *pFirstNode // simplification
-                                    : *iter->pNode),
+                            iter == *pIter
+                                ? *pFirstNode // simplification
+                                : *iter->pNode,
                             iter == *pIter // first extent?
                                 ? iter->pNode == pFirstNode
                                     ? 0 // at start of 1st node
@@ -1176,7 +1175,7 @@ static bool IsShown(SwNodeOffset const nIndex,
                     {
                         SwPosition const start(*iter->pNode, iter->nEnd);
                         SwPosition const end(
-                            const_cast<SwTextNode&>(*pLastNode), // 
simplification
+                            *pLastNode, // simplification
                             iter->pNode == pLastNode
                                 ? iter->pNode->Len()
                                 : 0);
diff --git a/sw/source/core/txtnode/modeltoviewhelper.cxx 
b/sw/source/core/txtnode/modeltoviewhelper.cxx
index e5aec1b510be..3796ff1e3e34 100644
--- a/sw/source/core/txtnode/modeltoviewhelper.cxx
+++ b/sw/source/core/txtnode/modeltoviewhelper.cxx
@@ -161,7 +161,7 @@ ModelToViewHelper::ModelToViewHelper(const SwTextNode 
&rNode,
             {
                 case CH_TXT_ATR_FIELDSTART:
                 {
-                    auto const 
pFieldMark(rIDMA.getFieldmarkAt(SwPosition(const_cast<SwTextNode&>(rNode), i)));
+                    auto const 
pFieldMark(rIDMA.getFieldmarkAt(SwPosition(rNode, i)));
                     assert(pFieldMark);
                     startedFields.emplace_back(pFieldMark, false);
                     if (!oStartHidden)
@@ -172,7 +172,7 @@ ModelToViewHelper::ModelToViewHelper(const SwTextNode 
&rNode,
                 }
                 case CH_TXT_ATR_FIELDSEP:
                 {
-                    
assert(startedFields.back().first->IsCoveringPosition(SwPosition(const_cast<SwTextNode&>(rNode),
 i)));
+                    
assert(startedFields.back().first->IsCoveringPosition(SwPosition(rNode, i)));
                     startedFields.back().second = true;
                     assert(oStartHidden);
                     if (::std::all_of(startedFields.begin(), 
startedFields.end(),
@@ -194,7 +194,7 @@ ModelToViewHelper::ModelToViewHelper(const SwTextNode 
&rNode,
                 }
                 case CH_TXT_ATR_FIELDEND:
                 {
-                    assert(startedFields.back().first == 
rIDMA.getFieldmarkAt(SwPosition(const_cast<SwTextNode&>(rNode), i)));
+                    assert(startedFields.back().first == 
rIDMA.getFieldmarkAt(SwPosition(rNode, i)));
                     startedFields.pop_back();
                     aHiddenMulti.Select({i, i}, true);
                     break;
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx 
b/sw/source/filter/ww8/wrtw8nds.cxx
index 5490b6b637dd..328356966937 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -2229,7 +2229,7 @@ bool MSWordExportBase::NeedTextNodeSplit( const 
SwTextNode& rNd, SwSoftPageBreak
         if (pos < it) // previous one might have skipped over it
         {
             pos = it;
-            while (auto const*const pMark = 
rIDMA.getFieldmarkFor(SwPosition(const_cast<SwTextNode&>(rNd), pos)))
+            while (auto const*const pMark = 
rIDMA.getFieldmarkFor(SwPosition(rNd, pos)))
             {
                 if (pMark->GetMarkEnd().nNode != rNd)
                 {
diff --git a/sw/source/uibase/utlui/content.cxx 
b/sw/source/uibase/utlui/content.cxx
index 132eecd13aa1..669b73aa3b5c 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -836,9 +836,9 @@ void SwContentType::FillMemberList(bool* pbContentChanged)
 
             std::stable_sort(aStableSortINetAttrsArray.begin(), 
aStableSortINetAttrsArray.end(),
                              [](const SwGetINetAttr* a, const SwGetINetAttr* 
b){
-                SwPosition 
aSwPos(const_cast<SwTextNode&>(a->rINetAttr.GetTextNode()),
+                SwPosition aSwPos(a->rINetAttr.GetTextNode(),
                                   a->rINetAttr.GetStart());
-                SwPosition 
bSwPos(const_cast<SwTextNode&>(b->rINetAttr.GetTextNode()),
+                SwPosition bSwPos(b->rINetAttr.GetTextNode(),
                                   b->rINetAttr.GetStart());
                 return aSwPos < bSwPos;});
 
@@ -850,8 +850,8 @@ void SwContentType::FillMemberList(bool* pbContentChanged)
                                  [nEndOfExtrasIndex](const SwGetINetAttr* a, 
const SwGetINetAttr* b){
                     const SwTextNode& aTextNode = a->rINetAttr.GetTextNode();
                     const SwTextNode& bTextNode = b->rINetAttr.GetTextNode();
-                    SwPosition aPos(const_cast<SwTextNode&>(aTextNode), 
a->rINetAttr.GetStart());
-                    SwPosition bPos(const_cast<SwTextNode&>(bTextNode), 
b->rINetAttr.GetStart());
+                    SwPosition aPos(aTextNode, a->rINetAttr.GetStart());
+                    SwPosition bPos(bTextNode, b->rINetAttr.GetStart());
                     // use anchor position for entries that are located in flys
                     if (nEndOfExtrasIndex >= aTextNode.GetIndex())
                         if (auto pFlyFormat = aTextNode.GetFlyFormat())

Reply via email to