From 1f5efbf8b9ba3fd5887c58574dfed3bf31cd020e Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Fri, 16 Feb 2024 23:58:01 +0600 Subject: Generalize search algorithms in sorted_vector This allows to simplify the code somewhat, and also to relax requirements to the arguments, e.g. allowing to pass const objects to search in vector containing non-const objects. Change-Id: Id34911a8694bbdec275d22b51ca4a0845c9fa4c4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163519 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- sw/source/core/doc/docredln.cxx | 2 +- sw/source/core/doc/doctxm.cxx | 4 ++-- sw/source/core/docnode/ndnum.cxx | 8 +++----- sw/source/core/docnode/node.cxx | 5 ++--- sw/source/core/edit/ednumber.cxx | 3 +-- sw/source/core/inc/docfld.hxx | 2 +- sw/source/core/inc/swblocks.hxx | 2 +- sw/source/filter/html/htmlfly.hxx | 2 +- sw/source/filter/html/wrthtml.hxx | 2 +- sw/source/filter/inc/wrtswtbl.hxx | 7 +++++-- sw/source/filter/xml/xmltble.cxx | 2 +- sw/source/uibase/docvw/OutlineContentVisibilityWin.cxx | 3 +-- sw/source/uibase/inc/dbinsdlg.hxx | 2 +- sw/source/uibase/inc/redlndlg.hxx | 2 +- sw/source/uibase/utlui/content.cxx | 2 +- 15 files changed, 23 insertions(+), 25 deletions(-) (limited to 'sw/source') diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx index 2c4ba6096c48..32696630e591 100644 --- a/sw/source/core/doc/docredln.cxx +++ b/sw/source/core/doc/docredln.cxx @@ -646,7 +646,7 @@ bool SwRedlineTable::InsertWithValidRanges(SwRangeRedline*& p, size_type* pInsPo return bAnyIns; } -bool CompareSwRedlineTable::operator()(SwRangeRedline* const &lhs, SwRangeRedline* const &rhs) const +bool CompareSwRedlineTable::operator()(const SwRangeRedline* lhs, const SwRangeRedline* rhs) const { return *lhs < *rhs; } diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx index 4b0ca5d323f1..af957c8a7318 100644 --- a/sw/source/core/doc/doctxm.cxx +++ b/sw/source/core/doc/doctxm.cxx @@ -754,7 +754,7 @@ static bool IsHeadingContained(const SwTextNode* pChptrNd, const SwNode& rNd) bool bCheckFirst = false; SwOutlineNodes::size_type nPos; - if (!rONds.Seek_Entry(const_cast(pNd), &nPos)) + if (!rONds.Seek_Entry(pNd, &nPos)) { if (nPos == 0) bCheckFirst = true; @@ -785,7 +785,7 @@ static bool IsHeadingContained(const SwTextNode* pChptrNd, const SwNode& rNd) if (bIsHeadingContained) { const SwNode* aChptrNd = pChptrNd; - if (!rONds.Seek_Entry(const_cast(aChptrNd), &nPos) && nPos) + if (!rONds.Seek_Entry(aChptrNd, &nPos) && nPos) nPos--; // Search for the next outline node with a larger level than the specified chapter node while (nPos < rONds.size() - 1 diff --git a/sw/source/core/docnode/ndnum.cxx b/sw/source/core/docnode/ndnum.cxx index af17a2a68e15..58b4cbff6488 100644 --- a/sw/source/core/docnode/ndnum.cxx +++ b/sw/source/core/docnode/ndnum.cxx @@ -24,12 +24,12 @@ #include #include -bool CompareSwOutlineNodes::operator()( SwNode* const& lhs, SwNode* const& rhs) const +bool CompareSwOutlineNodes::operator()(const SwNode* lhs, const SwNode* rhs) const { return lhs->GetIndex() < rhs->GetIndex(); } -bool SwOutlineNodes::Seek_Entry(SwNode* rP, size_type* pnPos) const +bool SwOutlineNodes::Seek_Entry(const SwNode* rP, size_type* pnPos) const { const_iterator it = lower_bound(rP); *pnPos = it - begin(); @@ -79,10 +79,8 @@ void SwNodes::UpdateOutlineIdx( const SwNode& rNd ) if( m_aOutlineNodes.empty() ) // no OutlineNodes present ? return; - SwNode* const pSrch = const_cast(&rNd); - SwOutlineNodes::size_type nPos; - if (!m_aOutlineNodes.Seek_Entry(pSrch, &nPos)) + if (!m_aOutlineNodes.Seek_Entry(&rNd, &nPos)) return; if( nPos == m_aOutlineNodes.size() ) // none present for updating ? return; diff --git a/sw/source/core/docnode/node.cxx b/sw/source/core/docnode/node.cxx index 0acdc1db91c3..ba3d9fdb6812 100644 --- a/sw/source/core/docnode/node.cxx +++ b/sw/source/core/docnode/node.cxx @@ -796,9 +796,8 @@ const SwTextNode* SwNode::FindOutlineNodeOfLevel(sal_uInt8 const nLvl, if( MAXLEVEL > nLvl && !rONds.empty() ) { SwOutlineNodes::size_type nPos; - SwNode* pNd = const_cast(this); bool bCheckFirst = false; - if( !rONds.Seek_Entry( pNd, &nPos )) + if (!rONds.Seek_Entry(this, &nPos)) { if (nPos == 0) bCheckFirst = true; @@ -2002,7 +2001,7 @@ bool SwContentNode::IsAnyCondition( SwCollCondition& rTmp ) const const SwOutlineNodes& rOutlNds = rNds.GetOutLineNds(); if( !rOutlNds.empty() ) { - if( !rOutlNds.Seek_Entry( const_cast(this), &nPos ) && nPos ) + if (!rOutlNds.Seek_Entry(this, &nPos) && nPos) --nPos; if( nPos < rOutlNds.size() && rOutlNds[ nPos ]->GetIndex() < GetIndex() ) diff --git a/sw/source/core/edit/ednumber.cxx b/sw/source/core/edit/ednumber.cxx index c272aa5f8eec..625cd43cb1c8 100644 --- a/sw/source/core/edit/ednumber.cxx +++ b/sw/source/core/edit/ednumber.cxx @@ -556,11 +556,10 @@ bool SwEditShell::IsProtectedOutlinePara() const if( rNd.IsTextNode() ) { const SwOutlineNodes& rOutlNd = GetDoc()->GetNodes().GetOutLineNds(); - SwNode* pNd = const_cast(&rNd); bool bFirst = true; SwOutlineNodes::size_type nPos; int nLvl(0); - if( !rOutlNd.Seek_Entry( pNd, &nPos ) && nPos ) + if (!rOutlNd.Seek_Entry(&rNd, &nPos) && nPos) --nPos; for( ; nPos < rOutlNd.size(); ++nPos ) diff --git a/sw/source/core/inc/docfld.hxx b/sw/source/core/inc/docfld.hxx index f09116978fb5..f0b4b261a8fe 100644 --- a/sw/source/core/inc/docfld.hxx +++ b/sw/source/core/inc/docfld.hxx @@ -114,7 +114,7 @@ public: void SetBodyPos( const SwContentFrame& rFrame ); }; -class SetGetExpFields : public o3tl::sorted_vector, o3tl::less_uniqueptr_to > +class SetGetExpFields : public o3tl::sorted_vector, o3tl::less_ptr_to > { }; diff --git a/sw/source/core/inc/swblocks.hxx b/sw/source/core/inc/swblocks.hxx index 7bd877ad653d..364f5f1a9ee8 100644 --- a/sw/source/core/inc/swblocks.hxx +++ b/sw/source/core/inc/swblocks.hxx @@ -49,7 +49,7 @@ public: bool operator< ( const SwBlockName& r ) const { return m_aShort < r.m_aShort; } }; -class SwBlockNames : public o3tl::sorted_vector, o3tl::less_uniqueptr_to > {}; +class SwBlockNames : public o3tl::sorted_vector, o3tl::less_ptr_to > {}; class SwImpBlocks { diff --git a/sw/source/filter/html/htmlfly.hxx b/sw/source/filter/html/htmlfly.hxx index 666f7730ecf9..4038ac2a2dcf 100644 --- a/sw/source/filter/html/htmlfly.hxx +++ b/sw/source/filter/html/htmlfly.hxx @@ -121,7 +121,7 @@ public: class SwHTMLPosFlyFrames : public o3tl::sorted_vector, - o3tl::less_uniqueptr_to, + o3tl::less_ptr_to, o3tl::find_partialorder_ptrequals> {}; diff --git a/sw/source/filter/html/wrthtml.hxx b/sw/source/filter/html/wrthtml.hxx index a62bff941a1d..51bd462d08d3 100644 --- a/sw/source/filter/html/wrthtml.hxx +++ b/sw/source/filter/html/wrthtml.hxx @@ -204,7 +204,7 @@ struct HTMLControl } }; -class HTMLControls : public o3tl::sorted_vector, o3tl::less_uniqueptr_to > { +class HTMLControls : public o3tl::sorted_vector, o3tl::less_ptr_to > { }; struct SwHTMLFormatInfo diff --git a/sw/source/filter/inc/wrtswtbl.hxx b/sw/source/filter/inc/wrtswtbl.hxx index e3391e7ce74c..83a40c0f681d 100644 --- a/sw/source/filter/inc/wrtswtbl.hxx +++ b/sw/source/filter/inc/wrtswtbl.hxx @@ -151,7 +151,7 @@ inline bool SwWriteTableRow::operator<( const SwWriteTableRow& rRow ) const } using SwWriteTableRows - = o3tl::sorted_vector< std::unique_ptr, o3tl::less_uniqueptr_to >; + = o3tl::sorted_vector< std::unique_ptr, o3tl::less_ptr_to >; class SwWriteTableCol { @@ -199,7 +199,10 @@ inline bool SwWriteTableCol::operator<( const SwWriteTableCol& rCol ) const } struct SwWriteTableColLess { - bool operator()(std::unique_ptr const & lhs, std::unique_ptr const & rhs) { + template + requires o3tl::is_reference_to + && o3tl::is_reference_to + bool operator()(T1 const& lhs, T2 const& rhs) const { return lhs->GetPos() < rhs->GetPos(); } }; diff --git a/sw/source/filter/xml/xmltble.cxx b/sw/source/filter/xml/xmltble.cxx index 1341bbbe37ad..ab61f071ce79 100644 --- a/sw/source/filter/xml/xmltble.cxx +++ b/sw/source/filter/xml/xmltble.cxx @@ -99,7 +99,7 @@ struct SwXMLTableColumnCmpWidth_Impl } }; -class SwXMLTableColumns_Impl : public o3tl::sorted_vector, o3tl::less_uniqueptr_to > { +class SwXMLTableColumns_Impl : public o3tl::sorted_vector, o3tl::less_ptr_to > { }; } diff --git a/sw/source/uibase/docvw/OutlineContentVisibilityWin.cxx b/sw/source/uibase/docvw/OutlineContentVisibilityWin.cxx index 998548550274..b7a21add98be 100644 --- a/sw/source/uibase/docvw/OutlineContentVisibilityWin.cxx +++ b/sw/source/uibase/docvw/OutlineContentVisibilityWin.cxx @@ -111,8 +111,7 @@ void SwOutlineContentVisibilityWin::Set() SwWrtShell& rSh = GetEditWin()->GetView().GetWrtShell(); const SwOutlineNodes& rOutlineNodes = rSh.GetNodes().GetOutLineNds(); - (void)rOutlineNodes.Seek_Entry(static_cast(const_cast(pTextNode)), - &m_nOutlinePos); + (void)rOutlineNodes.Seek_Entry(pTextNode, &m_nOutlinePos); // set symbol displayed on button bool bVisible = true; diff --git a/sw/source/uibase/inc/dbinsdlg.hxx b/sw/source/uibase/inc/dbinsdlg.hxx index 035bf49c6181..5694057990eb 100644 --- a/sw/source/uibase/inc/dbinsdlg.hxx +++ b/sw/source/uibase/inc/dbinsdlg.hxx @@ -73,7 +73,7 @@ struct SwInsDBColumn bool operator<( const SwInsDBColumn& rCmp ) const; }; -class SwInsDBColumns : public o3tl::sorted_vector, o3tl::less_uniqueptr_to > +class SwInsDBColumns : public o3tl::sorted_vector, o3tl::less_ptr_to > { }; diff --git a/sw/source/uibase/inc/redlndlg.hxx b/sw/source/uibase/inc/redlndlg.hxx index c8cfd8cc8262..d3944e9f81d9 100644 --- a/sw/source/uibase/inc/redlndlg.hxx +++ b/sw/source/uibase/inc/redlndlg.hxx @@ -51,7 +51,7 @@ struct SwRedlineDataParent { return (pData && pData->GetSeqNo() < rObj.pData->GetSeqNo()); } }; -class SwRedlineDataParentSortArr : public o3tl::sorted_vector > {}; +class SwRedlineDataParentSortArr : public o3tl::sorted_vector {}; class SW_DLLPUBLIC SwRedlineAcceptDlg final { diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx index fa1c7e10d447..8e301753b236 100644 --- a/sw/source/uibase/utlui/content.cxx +++ b/sw/source/uibase/utlui/content.cxx @@ -153,7 +153,7 @@ constexpr char NAVI_BOOKMARK_DELIM = '\x01'; } class SwContentArr - : public o3tl::sorted_vector, o3tl::less_uniqueptr_to, + : public o3tl::sorted_vector, o3tl::less_ptr_to, o3tl::find_partialorder_ptrequals> { }; -- cgit