include/svl/itemset.hxx | 4 ++ include/svx/unopage.hxx | 10 +++--- sc/inc/column.hxx | 4 +- sc/inc/patattr.hxx | 3 + sc/source/core/data/attarray.cxx | 4 +- sc/source/filter/excel/xetable.cxx | 10 +++--- svl/source/items/itemset.cxx | 29 +++++++++++++++++ svx/source/unodraw/unopage.cxx | 60 +++++++++++-------------------------- 8 files changed, 67 insertions(+), 57 deletions(-)
New commits: commit 661ed018fabf3c382867b91828fb8e69d359d9cb Author: Noel Grandin <[email protected]> AuthorDate: Wed Mar 27 16:25:44 2024 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Fri Mar 29 17:59:56 2024 +0100 convert SvxDrawPage to comphelper::WeakImplHelper Change-Id: I72ea1f08c3c531cee3ac9301aaf87c76f95de3f4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165549 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/include/svx/unopage.hxx b/include/svx/unopage.hxx index 82f643e29471..f1b5c81ec516 100644 --- a/include/svx/unopage.hxx +++ b/include/svx/unopage.hxx @@ -28,13 +28,14 @@ #include <com/sun/star/drawing/XShapeGrouper.hpp> #include <com/sun/star/lang/XUnoTunnel.hpp> #include <com/sun/star/form/XFormsSupplier2.hpp> -#include <cppuhelper/basemutex.hxx> #include <svx/svxdllapi.h> #include <svx/svdobjkind.hxx> #include <rtl/ref.hxx> #include <cppuhelper/implbase.hxx> #include <comphelper/servicehelper.hxx> +#include <comphelper/compbase.hxx> +#include <comphelper/interfacecontainer4.hxx> #include <memory> @@ -48,8 +49,8 @@ class SvxShapeGroup; class SvxShapeConnector; enum class SdrInventor : sal_uInt32; -class SVXCORE_DLLPUBLIC SvxDrawPage : protected cppu::BaseMutex, - public ::cppu::WeakImplHelper< css::drawing::XDrawPage, +class SVXCORE_DLLPUBLIC SvxDrawPage : + public ::comphelper::WeakImplHelper< css::drawing::XDrawPage, css::drawing::XShapeGrouper, css::drawing::XShapes2, css::drawing::XShapes3, @@ -60,8 +61,7 @@ class SVXCORE_DLLPUBLIC SvxDrawPage : protected cppu::BaseMutex, { protected: - cppu::OBroadcastHelper mrBHelper; - + comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> maEventListeners; SdrPage* mpPage; // TTTT should be reference SdrModel* mpModel; // TTTT probably not needed -> use from SdrPage std::unique_ptr<SdrView> mpView; diff --git a/svx/source/unodraw/unopage.cxx b/svx/source/unodraw/unopage.cxx index 0dcba14527ec..ffdc551893bc 100644 --- a/svx/source/unodraw/unopage.cxx +++ b/svx/source/unodraw/unopage.cxx @@ -66,8 +66,7 @@ using namespace ::com::sun::star::drawing; UNO3_GETIMPLEMENTATION_IMPL( SvxDrawPage ); SvxDrawPage::SvxDrawPage(SdrPage* pInPage) // TTTT should be reference -: mrBHelper(m_aMutex) - ,mpPage(pInPage) +: mpPage(pInPage) ,mpModel(&pInPage->getSdrModelFromSdrPage()) // register at broadcaster ,mpView(new SdrView(pInPage->getSdrModelFromSdrPage())) // create (hidden) view { @@ -76,7 +75,7 @@ SvxDrawPage::SvxDrawPage(SdrPage* pInPage) // TTTT should be reference SvxDrawPage::~SvxDrawPage() noexcept { - if( !mrBHelper.bDisposed ) + if( !m_bDisposed ) { assert(!"SvxDrawPage must be disposed!"); acquire(); @@ -108,67 +107,44 @@ void SvxDrawPage::dispose() // Guard dispose against multiple threading // Remark: It is an error to call dispose more than once - bool bDoDispose = false; { - osl::MutexGuard aGuard( mrBHelper.rMutex ); - if( !mrBHelper.bDisposed && !mrBHelper.bInDispose ) - { - // only one call go into this section - mrBHelper.bInDispose = true; - bDoDispose = true; - } + std::unique_lock aGuard( m_aMutex ); + if( m_bDisposed ) + return; + m_bDisposed = true; } - // Do not hold the mutex because we are broadcasting - if( !bDoDispose ) - return; - // Create an event with this as sender - try + css::document::EventObject aEvt; + aEvt.Source.set(uno::Reference<uno::XInterface>::query( static_cast<lang::XComponent *>(this) )); + // inform all listeners to release this object + // The listener container are automatically cleared { - css::document::EventObject aEvt; - aEvt.Source.set(uno::Reference<uno::XInterface>::query( static_cast<lang::XComponent *>(this) )); - // inform all listeners to release this object - // The listener container are automatically cleared - mrBHelper.aLC.disposeAndClear( aEvt ); - // notify subclasses to do their dispose - disposing(); + std::unique_lock aGuard( m_aMutex ); + maEventListeners.disposeAndClear( aGuard, aEvt ); } - catch(const css::uno::Exception&) - { - // catch exception and throw again but signal that - // the object was disposed. Dispose should be called - // only once. - osl::MutexGuard aGuard( mrBHelper.rMutex ); - mrBHelper.bDisposed = true; - mrBHelper.bInDispose = false; - throw; - } - - osl::MutexGuard aGuard( mrBHelper.rMutex ); - mrBHelper.bDisposed = true; - mrBHelper.bInDispose = false; - + // notify subclasses to do their dispose + disposing(); } void SAL_CALL SvxDrawPage::addEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) { - SolarMutexGuard aGuard; + std::unique_lock aGuard( m_aMutex ); if( mpModel == nullptr ) throw lang::DisposedException(); - mrBHelper.addListener( cppu::UnoType<decltype(aListener)>::get() , aListener ); + maEventListeners.addInterface( aGuard, aListener ); } void SAL_CALL SvxDrawPage::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) { - SolarMutexGuard aGuard; + std::unique_lock aGuard( m_aMutex ); if( mpModel == nullptr ) throw lang::DisposedException(); - mrBHelper.removeListener( cppu::UnoType<decltype(aListener)>::get() , aListener ); + maEventListeners.removeInterface( aGuard, aListener ); } void SAL_CALL SvxDrawPage::add( const uno::Reference< drawing::XShape >& xShape ) commit 117f4c05614a5c3f5d0495dab553f76a173dbeea Author: Noel Grandin <[email protected]> AuthorDate: Thu Mar 28 14:51:31 2024 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Fri Mar 29 17:59:45 2024 +0100 speed up ScPatternAttr we know that ScPatternAttr uses a single, contiguous range of item ids, so we can compute the item offset at compile time. Shaves 1-2% off some workloads. Change-Id: I623b8cb3e0d5d070118117196d2b48575f505725 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165550 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/include/svl/itemset.hxx b/include/svl/itemset.hxx index 3f1d3b2fd0e2..df0ffdcfd861 100644 --- a/include/svl/itemset.hxx +++ b/include/svl/itemset.hxx @@ -217,6 +217,10 @@ public: sal_uInt16 GetWhichByOffset(sal_uInt16 nOffset) const; + // Optimised variant for those situations where we know exactly what our which ranges are, + // and we can determine the offset at compile time. + const SfxPoolItem& GetByOffset(sal_uInt16 nWhich, sal_uInt16 nOffset) const; + SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent = true, const SfxPoolItem **ppItem = nullptr) const { // use local helper, start value for looped-through SfxItemState value is SfxItemState::UNKNOWN diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index bee768873a8e..9980ec1724b5 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -976,12 +976,12 @@ inline const ScPatternAttr* ScColumnData::GetPattern( SCROW nRow ) const inline const SfxPoolItem& ScColumnData::GetAttr( SCROW nRow, sal_uInt16 nWhich ) const { - return pAttrArray->GetPattern( nRow )->GetItemSet().Get(nWhich); + return pAttrArray->GetPattern( nRow )->GetItem(nWhich); } inline const SfxPoolItem& ScColumnData::GetAttr( SCROW nRow, sal_uInt16 nWhich, SCROW& nStartRow, SCROW& nEndRow ) const { - return pAttrArray->GetPatternRange( nStartRow, nEndRow, nRow )->GetItemSet().Get(nWhich); + return pAttrArray->GetPatternRange( nStartRow, nEndRow, nRow )->GetItem(nWhich); } inline sal_uInt32 ScColumnData::GetNumberFormat( const ScInterpreterContext& rContext, SCROW nRow ) const diff --git a/sc/inc/patattr.hxx b/sc/inc/patattr.hxx index 7294ff11fdaa..1dabeaa07102 100644 --- a/sc/inc/patattr.hxx +++ b/sc/inc/patattr.hxx @@ -28,6 +28,7 @@ #include "scdllapi.h" #include "fonthelper.hxx" #include "scitems.hxx" +#include "attrib.hxx" #include <unordered_set> namespace vcl { class Font; } @@ -137,7 +138,7 @@ public: const SfxItemSet& GetItemSet() const { return maLocalSfxItemSet; } SfxItemSet& GetItemSet() { return maLocalSfxItemSet; } - const SfxPoolItem& GetItem(sal_uInt16 nWhichP) const { return maLocalSfxItemSet.Get(nWhichP); } + const SfxPoolItem& GetItem(sal_uInt16 nWhichP) const { return maLocalSfxItemSet.GetByOffset(nWhichP, nWhichP - ATTR_PATTERN_START); } template<class T> const T& GetItem( TypedWhichId<T> nWhich ) const { return static_cast<const T&>(GetItem(sal_uInt16(nWhich))); } static const SfxPoolItem& GetItem(sal_uInt16 nWhich, const SfxItemSet& rItemSet, const SfxItemSet* pCondSet); diff --git a/sc/source/core/data/attarray.cxx b/sc/source/core/data/attarray.cxx index 95ab55903220..091dd4ba180b 100644 --- a/sc/source/core/data/attarray.cxx +++ b/sc/source/core/data/attarray.cxx @@ -1057,7 +1057,7 @@ static void lcl_MergeToFrame( SvxBoxItem* pLineOuter, SvxBoxInfoItem* pLineInner if ( rMerge.GetRowMerge() == nDistBottom + 1 ) nDistBottom = 0; - const SvxBoxItem* pCellFrame = &pPattern->GetItemSet().Get( ATTR_BORDER ); + const SvxBoxItem* pCellFrame = &pPattern->GetItem( ATTR_BORDER ); const SvxBorderLine* pLeftAttr = pCellFrame->GetLeft(); const SvxBorderLine* pRightAttr = pCellFrame->GetRight(); const SvxBorderLine* pTopAttr = pCellFrame->GetTop(); @@ -1159,7 +1159,7 @@ bool ScAttrArray::ApplyFrame( const SvxBoxItem& rBoxItem, OSL_ENSURE( pBoxInfoItem, "Missing line attributes!" ); const ScPatternAttr* pPattern = GetPattern( nStartRow ); - const SvxBoxItem* pOldFrame = &pPattern->GetItemSet().Get( ATTR_BORDER ); + const SvxBoxItem* pOldFrame = &pPattern->GetItem( ATTR_BORDER ); // right/bottom border set when connected together const ScMergeAttr& rMerge = pPattern->GetItem(ATTR_MERGE); diff --git a/sc/source/filter/excel/xetable.cxx b/sc/source/filter/excel/xetable.cxx index f7b9a81be9f0..3a9a02cbc6c2 100644 --- a/sc/source/filter/excel/xetable.cxx +++ b/sc/source/filter/excel/xetable.cxx @@ -745,7 +745,7 @@ void XclExpLabelCell::Init( const XclExpRoot& rRoot, if( GetXFId() == EXC_XFID_NOTFOUND ) { OSL_ENSURE( nXclFont != EXC_FONT_NOTFOUND, "XclExpLabelCell::Init - leading font not found" ); - bool bForceLineBreak = pPattern->GetItemSet().Get(ATTR_LINEBREAK ).GetValue(); + bool bForceLineBreak = pPattern->GetItem(ATTR_LINEBREAK ).GetValue(); SetXFId( rRoot.GetXFBuffer().InsertWithFont( pPattern, ApiScriptType::WEAK, nXclFont, bForceLineBreak ) ); } @@ -832,7 +832,7 @@ XclExpFormulaCell::XclExpFormulaCell( // current cell number format sal_uInt32 nScNumFmt = pPattern ? - pPattern->GetItemSet().Get( ATTR_VALUE_FORMAT ).GetValue() : + pPattern->GetItem( ATTR_VALUE_FORMAT ).GetValue() : rNumFmtBfr.GetStandardFormat(); // alternative number format passed to XF buffer @@ -2634,7 +2634,7 @@ XclExpCellTable::XclExpCellTable( const XclExpRoot& rRoot ) : if (pPattern) { - OUString aUrl = pPattern->GetItemSet().Get(ATTR_HYPERLINK).GetValue(); + OUString aUrl = pPattern->GetItem(ATTR_HYPERLINK).GetValue(); if (!aUrl.isEmpty()) { rtl::Reference<XclExpHyperlink> aLink = @@ -2646,7 +2646,7 @@ XclExpCellTable::XclExpCellTable( const XclExpRoot& rRoot ) : // try to create a Boolean cell if( pPattern && ((fValue == 0.0) || (fValue == 1.0)) ) { - sal_uInt32 nScNumFmt = pPattern->GetItemSet().Get( ATTR_VALUE_FORMAT ).GetValue(); + sal_uInt32 nScNumFmt = pPattern->GetItem( ATTR_VALUE_FORMAT ).GetValue(); if( rFormatter.GetType( nScNumFmt ) == SvNumFormatType::LOGICAL ) xCell = new XclExpBooleanCell( GetRoot(), aXclPos, pPattern, nMergeBaseXFId, fValue != 0.0 ); @@ -2691,7 +2691,7 @@ XclExpCellTable::XclExpCellTable( const XclExpRoot& rRoot ) : { if (pPattern) { - OUString aUrl = pPattern->GetItemSet().Get(ATTR_HYPERLINK).GetValue(); + OUString aUrl = pPattern->GetItem(ATTR_HYPERLINK).GetValue(); if (!aUrl.isEmpty()) { rtl::Reference<XclExpHyperlink> aLink = diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx index c9c7ceec3df1..3be339623ebc 100644 --- a/svl/source/items/itemset.cxx +++ b/svl/source/items/itemset.cxx @@ -1920,6 +1920,35 @@ sal_uInt16 SfxItemSet::GetWhichByOffset( sal_uInt16 nOffset ) const return GetRanges().getWhichFromOffset(nOffset); } +const SfxPoolItem& SfxItemSet::GetByOffset( sal_uInt16 nWhich, sal_uInt16 nOffset ) const +{ + assert(nOffset < TotalCount()); + + const_iterator aFoundOne(begin() + nOffset); + + if (nullptr != *aFoundOne) + { + if (IsInvalidItem(*aFoundOne)) + { + return GetPool()->GetUserOrPoolDefaultItem(nWhich); + } +#ifdef DBG_UTIL + if (IsDisabledItem(*aFoundOne)) + SAL_INFO("svl.items", "SFX_WARNING: Getting disabled Item"); +#endif + return **aFoundOne; + } + + if (nullptr != GetParent()) + { + return GetParent()->Get(nWhich, /*bSrchInParent*/true); + } + + // Get the Default from the Pool and return + assert(m_pPool); + return GetPool()->GetUserOrPoolDefaultItem(nWhich); +} + bool SfxItemSet::operator==(const SfxItemSet &rCmp) const { return Equals( rCmp, true);
