sw/inc/dcontact.hxx | 6 ++-- sw/inc/swtable.hxx | 2 + sw/source/core/bastyp/init.cxx | 2 - sw/source/core/crsr/crstrvl.cxx | 10 +++---- sw/source/core/doc/DocumentFieldsManager.cxx | 19 ++++++-------- sw/source/core/doc/docdraw.cxx | 7 ++--- sw/source/core/doc/doclay.cxx | 2 - sw/source/core/table/swnewtable.cxx | 6 ++-- sw/source/core/table/swtable.cxx | 35 ++++++++++++++++++++------- sw/source/core/undo/undraw.cxx | 4 +-- 10 files changed, 54 insertions(+), 39 deletions(-)
New commits: commit c659d65ce1c980bbf836ce95fbdb3729bf3234f1 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Fri Sep 6 13:41:22 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sat Sep 7 09:33:33 2024 +0200 dont use GetItemSurrogates for gathering SwTableBoxFormula which is very expensive these days Change-Id: If7ab76173e2b17fe767042a9461969babc16cb6e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172965 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/inc/swtable.hxx b/sw/inc/swtable.hxx index 7bc3ed0439ac..dc156ded1b30 100644 --- a/sw/inc/swtable.hxx +++ b/sw/inc/swtable.hxx @@ -368,6 +368,8 @@ public: void Merge(SwTable& rTable, SwHistory* pHistory); void Split(OUString sNewTableName, sal_uInt16 nSplitLine, SwHistory* pHistory); + static void GatherFormulas(SwDoc& rDoc, std::vector<SwTableBoxFormula*>& rvFormulas); + void dumpAsXml(xmlTextWriterPtr pWriter) const; }; diff --git a/sw/source/core/bastyp/init.cxx b/sw/source/core/bastyp/init.cxx index 2ec1f2266aa2..c673a1a2729b 100644 --- a/sw/source/core/bastyp/init.cxx +++ b/sw/source/core/bastyp/init.cxx @@ -455,7 +455,7 @@ ItemInfoPackage& getItemInfoPackageSwAttributes() { RES_GRFATR_DUMMY4, new SfxBoolItem( RES_GRFATR_DUMMY4 ), 0, SFX_ITEMINFOFLAG_NONE }, { RES_GRFATR_DUMMY5, new SfxBoolItem( RES_GRFATR_DUMMY5 ), 0, SFX_ITEMINFOFLAG_NONE }, { RES_BOXATR_FORMAT, new SwTableBoxNumFormat, 0, SFX_ITEMINFOFLAG_NONE }, - { RES_BOXATR_FORMULA, new SwTableBoxFormula( OUString() ), 0, SFX_ITEMINFOFLAG_SUPPORT_SURROGATE }, + { RES_BOXATR_FORMULA, new SwTableBoxFormula( OUString() ), 0, SFX_ITEMINFOFLAG_NONE }, { RES_BOXATR_VALUE, new SwTableBoxValue, 0, SFX_ITEMINFOFLAG_NONE }, { RES_UNKNOWNATR_CONTAINER, new SvXMLAttrContainerItem( RES_UNKNOWNATR_CONTAINER ), 0, SFX_ITEMINFOFLAG_SUPPORT_SURROGATE } }}; diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx index b2d640b8d695..dd30f73f88dc 100644 --- a/sw/source/core/crsr/crstrvl.cxx +++ b/sw/source/core/crsr/crstrvl.cxx @@ -416,17 +416,17 @@ bool SwCursorShell::GotoNxtPrvTableFormula( bool bNext, bool bOnlyErrors ) &rPos, &tmp) ); } - ItemSurrogates aSurrogates; - GetDoc()->GetAttrPool().GetItemSurrogates(aSurrogates, RES_BOXATR_FORMULA); - const sal_uInt32 nMaxItems(aSurrogates.size()); + std::vector<SwTableBoxFormula*> aTableBoxFormulas; + SwTable::GatherFormulas(*GetDoc(), aTableBoxFormulas); + const sal_uInt32 nMaxItems(aTableBoxFormulas.size()); if( nMaxItems > 0 ) { sal_uInt8 nMaxDo = 2; do { - for (const SfxPoolItem* pItem : aSurrogates) + for (SwTableBoxFormula* pItem : aTableBoxFormulas) { const SwTableBox* pTBox; - auto & rFormulaItem = static_cast<const SwTableBoxFormula&>(*pItem); + auto & rFormulaItem = *pItem; pTBox = rFormulaItem.GetTableBox(); if( pTBox && pTBox->GetSttNd() && diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx b/sw/source/core/doc/DocumentFieldsManager.cxx index d270ef6618d0..6b684dae4b73 100644 --- a/sw/source/core/doc/DocumentFieldsManager.cxx +++ b/sw/source/core/doc/DocumentFieldsManager.cxx @@ -614,14 +614,12 @@ void DocumentFieldsManager::UpdateTableFields(const SwTable* pTable) } } // process all table box formulas - ItemSurrogates aSurrogates; - m_rDoc.GetAttrPool().GetItemSurrogates(aSurrogates, RES_BOXATR_FORMULA); - for (const SfxPoolItem* pItem : aSurrogates) + std::vector<SwTableBoxFormula*> aTableBoxFormulas; + SwTable::GatherFormulas(m_rDoc, aTableBoxFormulas); + for (SwTableBoxFormula* pBoxFormula : aTableBoxFormulas) { - // SwTableBoxFormula is non-shareable, so const_cast is somewhat OK - auto & rBoxFormula = const_cast<SwTableBoxFormula&>(static_cast<const SwTableBoxFormula&>(*pItem)); - if(rBoxFormula.GetDefinedIn()) - rBoxFormula.ChangeState(); + if(pBoxFormula->GetDefinedIn()) + pBoxFormula->ChangeState(); } SwRootFrame const* pLayout(nullptr); @@ -716,11 +714,10 @@ void DocumentFieldsManager::UpdateTableFields(const SwTable* pTable) } // calculate the formula at the boxes - m_rDoc.GetAttrPool().GetItemSurrogates(aSurrogates, RES_BOXATR_FORMULA); - for (const SfxPoolItem* pItem : aSurrogates) + SwTable::GatherFormulas(m_rDoc, aTableBoxFormulas); + for (SwTableBoxFormula* pItem : aTableBoxFormulas) { - // SwTableBoxFormula is non-shareable, so const_cast is somewhat OK - auto & rFormula = const_cast<SwTableBoxFormula&>(static_cast<const SwTableBoxFormula&>(*pItem)); + auto & rFormula = *pItem; if(!rFormula.GetDefinedIn() || rFormula.IsValid()) continue; SwTableBox* pBox = rFormula.GetTableBox(); diff --git a/sw/source/core/table/swnewtable.cxx b/sw/source/core/table/swnewtable.cxx index 5d0464c46e04..bb2a7b0fbd70 100644 --- a/sw/source/core/table/swnewtable.cxx +++ b/sw/source/core/table/swnewtable.cxx @@ -2390,9 +2390,9 @@ bool SwTable::CanConvertSubtables() const { return false; // no formulas in fields yet } - ItemSurrogates aSurrogates; - pDoc->GetAttrPool().GetItemSurrogates(aSurrogates, RES_BOXATR_FORMULA); - if (!aSurrogates.empty()) + std::vector<SwTableBoxFormula*> aTableBoxFormulas; + SwTable::GatherFormulas(*pDoc, aTableBoxFormulas); + if (!aTableBoxFormulas.empty()) { return false; // no table box formulas yet } diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx index e4d066e4c22d..73d71a6df459 100644 --- a/sw/source/core/table/swtable.cxx +++ b/sw/source/core/table/swtable.cxx @@ -1623,17 +1623,34 @@ bool SwTable::IsDeleted() const void SwTable::GatherFormulas(std::vector<SwTableBoxFormula*>& rvFormulas) { - ItemSurrogates aSurrogates; - GetFrameFormat()->GetDoc()->GetAttrPool().GetItemSurrogates(aSurrogates, RES_BOXATR_FORMULA); - for(const SfxPoolItem* pItem: aSurrogates) + GatherFormulas(*GetFrameFormat()->GetDoc(), rvFormulas); +} + +void SwTable::GatherFormulas(SwDoc& rDoc, std::vector<SwTableBoxFormula*>& rvFormulas) +{ + rvFormulas.clear(); + sw::TableFrameFormats* pTableFrameFormats = rDoc.GetTableFrameFormats(); + for(SwTableFormat* pFormat : *pTableFrameFormats) { - const auto & rBoxFormula = static_cast<const SwTableBoxFormula&>(*pItem); - if(!rBoxFormula.GetDefinedIn()) + SwTable* pTable = FindTable(pFormat); + if (!pTable) continue; - const SwNode* pNd = rBoxFormula.GetNodeOfFormula(); - if(!pNd || &pNd->GetNodes() != &pNd->GetDoc().GetNodes()) // is this ever valid or should we assert here? - continue; - rvFormulas.push_back(const_cast<SwTableBoxFormula*>(&rBoxFormula)); + SwTableLines& rTableLines = pTable->GetTabLines(); + for (SwTableLine* pTableLine : rTableLines) + { + SwTableBoxes& rTableBoxes = pTableLine->GetTabBoxes(); + for (SwTableBox* pTableBox : rTableBoxes) + { + SwTableBoxFormat* pTableBoxFormat = pTableBox->GetFrameFormat(); + if (const SwTableBoxFormula* pBoxFormula = pTableBoxFormat->GetItemIfSet( RES_BOXATR_FORMULA, false )) + { + const SwNode* pNd = pBoxFormula->GetNodeOfFormula(); + if(!pNd || &pNd->GetNodes() != &pNd->GetDoc().GetNodes()) // is this ever valid or should we assert here? + continue; + rvFormulas.push_back(const_cast<SwTableBoxFormula*>(pBoxFormula)); + } + } + } } } commit 43be09b29c28284c6585eaa48117e168f7c9c7b5 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Fri Sep 6 15:27:43 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sat Sep 7 09:33:22 2024 +0200 return SwDrawFrameFormat from SwContact::GetFrameFormat since that is always the SwFrameFormat subclass we are attached to Change-Id: Icdd7cb162c9778aa4d63227f1a69c1c41eef3db2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172969 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/inc/dcontact.hxx b/sw/inc/dcontact.hxx index 3b09f0e3fd68..86d816111ace 100644 --- a/sw/inc/dcontact.hxx +++ b/sw/inc/dcontact.hxx @@ -109,9 +109,9 @@ public: virtual const SdrObject *GetMaster() const = 0; virtual SdrObject *GetMaster() = 0; - SwFrameFormat *GetFormat() { return static_cast<SwFrameFormat*>(GetRegisteredIn()); } - const SwFrameFormat *GetFormat() const - { return static_cast<const SwFrameFormat*>(GetRegisteredIn()); } + SwDrawFrameFormat *GetFormat() { return static_cast<SwDrawFrameFormat*>(GetRegisteredIn()); } + const SwDrawFrameFormat *GetFormat() const + { return static_cast<const SwDrawFrameFormat*>(GetRegisteredIn()); } bool IsInDTOR() const { return mbInDTOR;} diff --git a/sw/source/core/doc/docdraw.cxx b/sw/source/core/doc/docdraw.cxx index 862945fb3bd5..0be34d8f9c9f 100644 --- a/sw/source/core/doc/docdraw.cxx +++ b/sw/source/core/doc/docdraw.cxx @@ -239,7 +239,7 @@ SwDrawContact* SwDoc::GroupSelection( SdrView& rDrawView ) for (const auto& rTextBoxElement : pTextBoxNode->GetAllTextBoxes()) vSavedTextBoxes.emplace(rTextBoxElement); - pFormat = static_cast<SwDrawFrameFormat*>(pContact->GetFormat()); + pFormat = pContact->GetFormat(); // Deletes itself! pContact->Changed(*pObj, SdrUserCallType::Delete, pObj->GetLastBoundRect() ); pObj->SetUserCall( nullptr ); @@ -478,8 +478,7 @@ bool SwDoc::DeleteSelection( SwDrawView& rDrawView ) { if (SwDrawContact* pC = static_cast<SwDrawContact*>(GetUserCall(pObj))) { - SwDrawFrameFormat* pFrameFormat - = static_cast<SwDrawFrameFormat*>(pC->GetFormat()); + SwDrawFrameFormat* pFrameFormat = pC->GetFormat(); if (pFrameFormat && RndStdIds::FLY_AS_CHAR == pFrameFormat->GetAnchor().GetAnchorId()) { @@ -509,7 +508,7 @@ bool SwDoc::DeleteSelection( SwDrawView& rDrawView ) SwDrawContact *pContact = static_cast<SwDrawContact*>(pObj->GetUserCall()); if( pContact ) // of course not for grouped objects { - SwDrawFrameFormat *pFormat = static_cast<SwDrawFrameFormat*>(pContact->GetFormat()); + SwDrawFrameFormat *pFormat = pContact->GetFormat(); // before delete of selection is performed, marked // <SwDrawVirtObj>-objects have to be replaced by its // reference objects. Thus, assert, if a diff --git a/sw/source/core/doc/doclay.cxx b/sw/source/core/doc/doclay.cxx index 9353610dcb96..bca8a652eae3 100644 --- a/sw/source/core/doc/doclay.cxx +++ b/sw/source/core/doc/doclay.cxx @@ -1247,7 +1247,7 @@ SwFlyFrameFormat* SwDoc::InsertDrawLabel( OSL_ENSURE( RES_DRAWFRMFMT == pContact->GetFormat()->Which(), "InsertDrawLabel(): not a DrawFrameFormat" ); - SwDrawFrameFormat* pOldFormat = static_cast<SwDrawFrameFormat *>(pContact->GetFormat()); + SwDrawFrameFormat* pOldFormat = pContact->GetFormat(); if (!pOldFormat) return nullptr; diff --git a/sw/source/core/undo/undraw.cxx b/sw/source/core/undo/undraw.cxx index 2365c9b57156..f40d03033636 100644 --- a/sw/source/core/undo/undraw.cxx +++ b/sw/source/core/undo/undraw.cxx @@ -354,7 +354,7 @@ SwUndoDrawUnGroup::SwUndoDrawUnGroup( SdrObjGroup* pObj, const SwDoc& rDoc ) if (SwDrawContact *pContact = static_cast<SwDrawContact*>(GetUserCall(pObj))) { - SwDrawFrameFormat* pFormat = static_cast<SwDrawFrameFormat*>(pContact->GetFormat()); + SwDrawFrameFormat* pFormat = pContact->GetFormat(); m_pObjArray[0].pObj = pObj; m_pObjArray[0].pFormat = pFormat; @@ -629,7 +629,7 @@ void SwUndoDrawDelete::RedoImpl(::sw::UndoRedoContext & rContext) if (!pContact) continue; - SwDrawFrameFormat *pFormat = static_cast<SwDrawFrameFormat*>(pContact->GetFormat()); + SwDrawFrameFormat *pFormat = pContact->GetFormat(); // object will destroy itself pContact->Changed( *pObj, SdrUserCallType::Delete, pObj->GetLastBoundRect() );