sw/inc/unochart.hxx | 17 ++---------- sw/inc/unoparagraph.hxx | 8 ----- sw/source/core/unocore/unochart.cxx | 43 ++++++++++++++++++-------------- sw/source/core/unocore/unodraw.cxx | 2 - sw/source/core/unocore/unoobj2.cxx | 2 - sw/source/core/unocore/unoparagraph.cxx | 12 -------- sw/source/core/unocore/unotext.cxx | 6 +--- sw/source/uibase/uno/unotxvw.cxx | 2 - 8 files changed, 34 insertions(+), 58 deletions(-)
New commits: commit 70eb1c9838bf9ab7650318381e7d48f811e761d4 Author: Noel Grandin <[email protected]> AuthorDate: Wed Jan 18 12:41:50 2023 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Thu Jan 19 17:55:44 2023 +0000 XUnoTunnel->dynamic_cast in SwXParagraph Change-Id: Ib39e51900826b13824906c33775a8aa375955fcd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145780 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/sw/inc/unoparagraph.hxx b/sw/inc/unoparagraph.hxx index ab1bb903a7cd..860edc18e938 100644 --- a/sw/inc/unoparagraph.hxx +++ b/sw/inc/unoparagraph.hxx @@ -22,7 +22,6 @@ #include <memory> -#include <com/sun/star/lang/XUnoTunnel.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertyState.hpp> @@ -49,7 +48,6 @@ class SwXTextPortionEnumeration; typedef ::cppu::ImplInheritanceHelper < ::sfx2::MetadatableMixin -, css::lang::XUnoTunnel , css::lang::XServiceInfo , css::beans::XPropertySet , css::beans::XPropertyState @@ -99,12 +97,6 @@ public: virtual css::uno::Reference< css::frame::XModel > GetModel() override; - static const css::uno::Sequence< sal_Int8 >& getUnoTunnelId(); - - // XUnoTunnel - virtual sal_Int64 SAL_CALL getSomething( - const css::uno::Sequence< sal_Int8 >& rIdentifier) override; - // XServiceInfo virtual OUString SAL_CALL getImplementationName() override; virtual sal_Bool SAL_CALL supportsService( diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx index 00685756c39d..a11dff3a87cc 100644 --- a/sw/source/core/unocore/unodraw.cxx +++ b/sw/source/core/unocore/unodraw.cxx @@ -1995,7 +1995,7 @@ void SwXShape::attach(const uno::Reference< text::XTextRange > & xTextRange) pDoc = pCursor->GetDoc(); else if (auto pPortion = comphelper::getFromUnoTunnel<SwXTextPortion>(xRangeTunnel)) pDoc = &pPortion->GetCursor().GetDoc(); - else if (auto pParagraph = comphelper::getFromUnoTunnel<SwXParagraph>(xRangeTunnel); + else if (auto pParagraph = dynamic_cast<SwXParagraph*>(xTextRange.get()); pParagraph && pParagraph->GetTextNode()) pDoc = &pParagraph->GetTextNode()->GetDoc(); diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx index a40e92a92cec..87abdf72ffd1 100644 --- a/sw/source/core/unocore/unoobj2.cxx +++ b/sw/source/core/unocore/unoobj2.cxx @@ -1111,7 +1111,7 @@ bool XTextRangeToSwPaM( SwUnoInternalPaM & rToFill, OTextCursorHelper* pCursor = dynamic_cast<OTextCursorHelper*>(xTextRange.get()); SwXTextPortion* pPortion = comphelper::getFromUnoTunnel<SwXTextPortion>(xRangeTunnel); SwXText* pText = dynamic_cast<SwXText*>(xTextRange.get()); - SwXParagraph* pPara = comphelper::getFromUnoTunnel<SwXParagraph>(xRangeTunnel); + SwXParagraph* pPara = dynamic_cast<SwXParagraph*>(xTextRange.get()); SwXHeadFootText* pHeadText = eMode == TextRangeMode::AllowTableNode ? dynamic_cast<SwXHeadFootText*>(pText) : nullptr; diff --git a/sw/source/core/unocore/unoparagraph.cxx b/sw/source/core/unocore/unoparagraph.cxx index a41f11ef873c..55c71ca730a4 100644 --- a/sw/source/core/unocore/unoparagraph.cxx +++ b/sw/source/core/unocore/unoparagraph.cxx @@ -295,18 +295,6 @@ bool SwXParagraph::SelectPaM(SwPaM & rPaM) return true; } -const uno::Sequence< sal_Int8 > & SwXParagraph::getUnoTunnelId() -{ - static const comphelper::UnoIdInit theSwXParagraphUnoTunnelId; - return theSwXParagraphUnoTunnelId.getSeq(); -} - -sal_Int64 SAL_CALL -SwXParagraph::getSomething(const uno::Sequence< sal_Int8 >& rId) -{ - return comphelper::getSomethingImpl<SwXParagraph>(rId, this); -} - OUString SAL_CALL SwXParagraph::getImplementationName() { diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx index b38c14c9e5fe..6248e0dfc8e3 100644 --- a/sw/source/core/unocore/unotext.cxx +++ b/sw/source/core/unocore/unotext.cxx @@ -636,8 +636,7 @@ SwXText::insertTextContentBefore( throw aRuntime; } - SwXParagraph *const pPara = - comphelper::getFromUnoTunnel<SwXParagraph>(xNewContent); + SwXParagraph *const pPara = dynamic_cast<SwXParagraph*>(xNewContent.get()); if (!pPara || !pPara->IsDescriptor() || !xSuccessor.is()) { throw lang::IllegalArgumentException(); @@ -692,8 +691,7 @@ SwXText::insertTextContentAfter( throw uno::RuntimeException(); } - SwXParagraph *const pPara = - comphelper::getFromUnoTunnel<SwXParagraph>(xNewContent); + SwXParagraph *const pPara = dynamic_cast<SwXParagraph*>(xNewContent.get()); if(!pPara || !pPara->IsDescriptor() || !xPredecessor.is()) { throw lang::IllegalArgumentException(); diff --git a/sw/source/uibase/uno/unotxvw.cxx b/sw/source/uibase/uno/unotxvw.cxx index 7232e98136a6..953b430a4314 100644 --- a/sw/source/uibase/uno/unotxvw.cxx +++ b/sw/source/uibase/uno/unotxvw.cxx @@ -990,7 +990,7 @@ void SwXTextViewCursor::gotoRange( uno::Reference<lang::XUnoTunnel> xRangeTunnel( xRange, uno::UNO_QUERY); SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel); - SwXParagraph* pPara = comphelper::getFromUnoTunnel<SwXParagraph>(xRangeTunnel); + SwXParagraph* pPara = dynamic_cast<SwXParagraph*>(xRange.get()); OTextCursorHelper* pCursor = dynamic_cast<OTextCursorHelper*>(xRange.get()); const FrameTypeFlags nFrameType = rSh.GetFrameType(nullptr,true); commit bbe9d53fab5212040867adaa0cd6341d50ae244d Author: Noel Grandin <[email protected]> AuthorDate: Wed Jan 18 11:16:13 2023 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Thu Jan 19 17:55:31 2023 +0000 storing WeakReference in std::set is a bad idea because if we allocate two things in the same location, we can subtlely lose the second one. Change-Id: I4dda5c738802da8544d280c020e059da63b5d71c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145779 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/sw/inc/unochart.hxx b/sw/inc/unochart.hxx index d56b3356da0a..956d5f721e94 100644 --- a/sw/inc/unochart.hxx +++ b/sw/inc/unochart.hxx @@ -20,7 +20,7 @@ #define INCLUDED_SW_INC_UNOCHART_HXX #include <map> -#include <set> +#include <vector> #include <com/sun/star/chart2/data/XDataProvider.hpp> #include <com/sun/star/chart2/data/XDataSource.hpp> @@ -105,20 +105,11 @@ class SwChartDataProvider final : { // used to keep weak-references to all data-sequences of a single table - // see set definition below... - struct lt_DataSequenceRef - { - bool operator()( const unotools::WeakReference< SwChartDataSequence > & xWRef1, const unotools::WeakReference< SwChartDataSequence >& xWRef2 ) const - { - rtl::Reference< SwChartDataSequence > xRef1( xWRef1 ); - rtl::Reference< SwChartDataSequence > xRef2( xWRef2 ); - return xRef1.get() < xRef2.get(); - } - }; - typedef std::set< unotools::WeakReference < SwChartDataSequence >, lt_DataSequenceRef > Set_DataSequenceRef_t; + // see definition below... + typedef std::vector< unotools::WeakReference < SwChartDataSequence > > Vec_DataSequenceRef_t; // map of data-sequence sets for each table - typedef std::map< const SwTable *, Set_DataSequenceRef_t > Map_Set_DataSequenceRef_t; + typedef std::map< const SwTable *, Vec_DataSequenceRef_t > Map_Set_DataSequenceRef_t; // map of all data-sequences provided directly or indirectly (e.g. via // data-source) by this object. Since there is only one object of this type diff --git a/sw/source/core/unocore/unochart.cxx b/sw/source/core/unocore/unochart.cxx index 14be7d0c711e..40fa3b0fe882 100644 --- a/sw/source/core/unocore/unochart.cxx +++ b/sw/source/core/unocore/unochart.cxx @@ -1405,12 +1405,23 @@ uno::Sequence< OUString > SAL_CALL SwChartDataProvider::getSupportedServiceNames void SwChartDataProvider::AddDataSequence( const SwTable &rTable, rtl::Reference< SwChartDataSequence > const &rxDataSequence ) { - m_aDataSequences[ &rTable ].insert( rxDataSequence ); + Vec_DataSequenceRef_t& rVec = m_aDataSequences[ &rTable ]; + assert(std::find_if(rVec.begin(), rVec.end(), + [&rxDataSequence](const unotools::WeakReference < SwChartDataSequence >& i) + { + return i.get() == rxDataSequence; + }) == rVec.end() && "duplicate insert"); + rVec.push_back( rxDataSequence ); } void SwChartDataProvider::RemoveDataSequence( const SwTable &rTable, rtl::Reference< SwChartDataSequence > const &rxDataSequence ) { - m_aDataSequences[ &rTable ].erase( rxDataSequence ); + Vec_DataSequenceRef_t& rVec = m_aDataSequences[ &rTable ]; + rVec.erase( std::remove_if(rVec.begin(), rVec.end(), + [&rxDataSequence](const unotools::WeakReference < SwChartDataSequence >& i) + { + return i.get() == rxDataSequence; + }), rVec.end()); } void SwChartDataProvider::InvalidateTable( const SwTable *pTable, bool bImmediate ) @@ -1422,8 +1433,8 @@ void SwChartDataProvider::InvalidateTable( const SwTable *pTable, bool bImmediat if (!m_bDisposed) pTable->GetFrameFormat()->GetDoc()->getIDocumentChartDataProviderAccess().GetChartControllerHelper().StartOrContinueLocking(); - const Set_DataSequenceRef_t &rSet = m_aDataSequences[ pTable ]; - for (const unotools::WeakReference<SwChartDataSequence>& rItem : rSet) + const Vec_DataSequenceRef_t &rVec = m_aDataSequences[ pTable ]; + for (const unotools::WeakReference<SwChartDataSequence>& rItem : rVec) { rtl::Reference< SwChartDataSequence > xRef(rItem); if (xRef.is()) @@ -1447,13 +1458,11 @@ void SwChartDataProvider::DeleteBox( const SwTable *pTable, const SwTableBox &rB if (!m_bDisposed) pTable->GetFrameFormat()->GetDoc()->getIDocumentChartDataProviderAccess().GetChartControllerHelper().StartOrContinueLocking(); - Set_DataSequenceRef_t &rSet = m_aDataSequences[ pTable ]; + Vec_DataSequenceRef_t &rVec = m_aDataSequences[ pTable ]; // iterate over all data-sequences for that table... - Set_DataSequenceRef_t::iterator aIt( rSet.begin() ); - Set_DataSequenceRef_t::iterator aEndIt( rSet.end() ); - Set_DataSequenceRef_t::iterator aDelIt; // iterator used for deletion when appropriate - while (aIt != aEndIt) + auto aIt( rVec.begin() ); + while (aIt != rVec.end()) { bool bNowEmpty = false; bool bSeqDisposed = false; @@ -1472,18 +1481,16 @@ void SwChartDataProvider::DeleteBox( const SwTable *pTable, const SwTableBox &rB bNowEmpty = true; bSeqDisposed = true; } - - if (bNowEmpty) - aDelIt = aIt; } - ++aIt; if (bNowEmpty) { - rSet.erase( aDelIt ); + aIt = rVec.erase( aIt ); if (pDataSeq && !bSeqDisposed) pDataSeq->dispose(); // the current way to tell chart that sth. got removed } + else + ++aIt; } } @@ -1500,9 +1507,9 @@ void SwChartDataProvider::DisposeAllDataSequences( const SwTable *pTable ) //! This is necessary since calling 'dispose' will implicitly remove an element //! of the original container, and thus any iterator in the original container //! would become invalid. - const Set_DataSequenceRef_t aSet( m_aDataSequences[ pTable ] ); + const Vec_DataSequenceRef_t aVec( m_aDataSequences[ pTable ] ); - for (const unotools::WeakReference<SwChartDataSequence>& rItem : aSet) + for (const unotools::WeakReference<SwChartDataSequence>& rItem : aVec) { rtl::Reference< SwChartDataSequence > xRef(rItem); if (xRef.is()) @@ -1572,8 +1579,8 @@ void SwChartDataProvider::AddRowCols( } // iterate over all data-sequences for the table - const Set_DataSequenceRef_t &rSet = m_aDataSequences[ &rTable ]; - for (const unotools::WeakReference<SwChartDataSequence>& rItem : rSet) + const Vec_DataSequenceRef_t &rVec = m_aDataSequences[ &rTable ]; + for (const unotools::WeakReference<SwChartDataSequence>& rItem : rVec) { rtl::Reference< SwChartDataSequence > pDataSeq(rItem); if (pDataSeq.is())
