From 9f2e368e763a4ae595804567137dcd2537a3d60f Mon Sep 17 00:00:00 2001 From: RashmiVid Date: Fri, 27 Mar 2026 03:33:54 -0400 Subject: [PATCH] tdf#145538 Use range based for loops in tblafmt.cxx and ndtbl1.cxx Replace index basedloops with range based loops where safe. No functional change intended. Change-Id: I9b6ed9a03d4a35d809f3049c371efa7d1f43e060 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/202787 Reviewed-by: Dmitriy Usov Tested-by: Jenkins Reviewed-by: Jonathan Clark --- sw/source/core/doc/tblafmt.cxx | 18 +++++++++--------- sw/source/core/docnode/ndtbl1.cxx | 16 +++++++--------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/sw/source/core/doc/tblafmt.cxx b/sw/source/core/doc/tblafmt.cxx index e6d65ab7c8ed..89c97483f72c 100644 --- a/sw/source/core/doc/tblafmt.cxx +++ b/sw/source/core/doc/tblafmt.cxx @@ -854,10 +854,10 @@ void SwCellStyleTable::RemoveBoxFormat(const OUString& sName) UIName SwCellStyleTable::GetBoxFormatName(const SwBoxAutoFormat& rBoxFormat) const { - for (size_t i = 0; i < m_aCellStyles.size(); ++i) + for (const auto& rCellStyle : m_aCellStyles) { - if (m_aCellStyles[i].second.get() == &rBoxFormat) - return m_aCellStyles[i].first; + if (rCellStyle.second.get() == &rBoxFormat) + return rCellStyle.first; } // box format not found @@ -866,10 +866,10 @@ UIName SwCellStyleTable::GetBoxFormatName(const SwBoxAutoFormat& rBoxFormat) con SwBoxAutoFormat* SwCellStyleTable::GetBoxFormat(const UIName& sName) const { - for (size_t i = 0; i < m_aCellStyles.size(); ++i) + for (const auto& rCellStyle : m_aCellStyles) { - if (m_aCellStyles[i].first == sName) - return m_aCellStyles[i].second.get(); + if (rCellStyle.first == sName) + return rCellStyle.second.get(); } return nullptr; @@ -882,11 +882,11 @@ void SwCellStyleTable::ChangeBoxFormatName(std::u16string_view sFromName, const SAL_INFO("sw.core", "SwCellStyleTable::ChangeBoxName, box with given name already exists"); return; } - for (size_t i = 0; i < m_aCellStyles.size(); ++i) + for (auto& rCellStyle : m_aCellStyles) { - if (m_aCellStyles[i].first == sFromName) + if (rCellStyle.first == sFromName) { - m_aCellStyles[i].first = sToName; + rCellStyle.first = sToName; // changed successfully return; } diff --git a/sw/source/core/docnode/ndtbl1.cxx b/sw/source/core/docnode/ndtbl1.cxx index 65e27964d4e6..ee7005f73d6b 100644 --- a/sw/source/core/docnode/ndtbl1.cxx +++ b/sw/source/core/docnode/ndtbl1.cxx @@ -1288,10 +1288,8 @@ void SwDoc::SetBoxAttr( const SwCursor& rCursor, const SfxPoolItem &rNew ) std::vector> aFormatCmp; aFormatCmp.reserve(std::max(255, aBoxes.size())); - for (size_t i = 0; i < aBoxes.size(); ++i) + for (auto pBox : aBoxes) { - SwTableBox *pBox = aBoxes[i]; - SwFrameFormat *pNewFormat = SwTableFormatCmp::FindNewFormat( aFormatCmp, pBox->GetFrameFormat(), 0 ); if ( nullptr != pNewFormat ) pBox->ChgFrameFormat( static_cast(pNewFormat) ); @@ -1330,14 +1328,14 @@ bool SwDoc::GetBoxAttr( const SwCursor& rCursor, std::unique_ptr& r bRet = true; bool bOneFound = false; const sal_uInt16 nWhich = rToFill->Which(); - for (size_t i = 0; i < aBoxes.size(); ++i) + for (auto pBox : aBoxes) { switch ( nWhich ) { case RES_BACKGROUND: { std::unique_ptr xBack = - aBoxes[i]->GetFrameFormat()->makeBackgroundBrushItem(); + pBox->GetFrameFormat()->makeBackgroundBrushItem(); if( !bOneFound ) { rToFill = std::move(xBack); @@ -1351,7 +1349,7 @@ bool SwDoc::GetBoxAttr( const SwCursor& rCursor, std::unique_ptr& r case RES_FRAMEDIR: { const SvxFrameDirectionItem& rDir = - aBoxes[i]->GetFrameFormat()->GetFrameDir(); + pBox->GetFrameFormat()->GetFrameDir(); if( !bOneFound ) { rToFill.reset(rDir.Clone()); @@ -1364,7 +1362,7 @@ bool SwDoc::GetBoxAttr( const SwCursor& rCursor, std::unique_ptr& r case RES_VERT_ORIENT: { const SwFormatVertOrient& rOrient = - aBoxes[i]->GetFrameFormat()->GetVertOrient(); + pBox->GetFrameFormat()->GetVertOrient(); if( !bOneFound ) { rToFill.reset(rOrient.Clone()); @@ -1399,10 +1397,10 @@ sal_uInt16 SwDoc::GetBoxAlign( const SwCursor& rCursor ) SwSelBoxes aBoxes; if( pTableNd && ::lcl_GetBoxSel( rCursor, aBoxes )) { - for (size_t i = 0; i < aBoxes.size(); ++i) + for (auto pBox : aBoxes) { const SwFormatVertOrient &rOri = - aBoxes[i]->GetFrameFormat()->GetVertOrient(); + pBox->GetFrameFormat()->GetVertOrient(); if( USHRT_MAX == nAlign ) nAlign = o3tl::narrowing(rOri.GetVertOrient()); else if( rOri.GetVertOrient() != nAlign )