From 01144d08d9bd9141aa7a11104b2a7b35ca25f36a Mon Sep 17 00:00:00 2001 From: Muhammad Naeem Date: Sat, 2 May 2026 14:28:16 +0500 Subject: [PATCH] tdf#145538: Prefer range-based for in svtools, Sfx2, DDE client Replace a few index loops with range-based iteration where the counter was only used for element access: index algorithm lookup, UTF-16 OLE string streaming, and scanning DDE connections for a matching handle. Verification: make svtools sfx2 Change-Id: I5678af4bdab855d7ce60bdccc46f608cee56c4e8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204657 Reviewed-by: Julien Nabet Tested-by: Julien Nabet --- sfx2/source/doc/oleprops.cxx | 4 ++-- svl/source/svdde/ddecli.cxx | 9 +++++---- svtools/source/control/indexentryres.cxx | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/sfx2/source/doc/oleprops.cxx b/sfx2/source/doc/oleprops.cxx index 1ba8b4eaf48d..d9c57b0d0c29 100644 --- a/sfx2/source/doc/oleprops.cxx +++ b/sfx2/source/doc/oleprops.cxx @@ -326,8 +326,8 @@ void SfxOleStringHelper::ImplSaveString16( SvStream& rStrm, std::u16string_view sal_Int32 nSize = static_cast< sal_Int32 >( rValue.size() + 1 ); rStrm.WriteInt32( nSize ); // write character array with trailing NUL character - for( size_t nIdx = 0; nIdx < rValue.size(); ++nIdx ) - rStrm.WriteUInt16( rValue[ nIdx ] ); + for( char16_t c : rValue ) + rStrm.WriteUInt16( c ); rStrm.WriteUInt16( 0 ); // stream is always padded to 32-bit boundary, add 2 bytes on odd character count if( (nSize & 1) == 1 ) diff --git a/svl/source/svdde/ddecli.cxx b/svl/source/svdde/ddecli.cxx index bcc2d61c2e8d..009dcbbc114c 100644 --- a/svl/source/svdde/ddecli.cxx +++ b/svl/source/svdde/ddecli.cxx @@ -51,12 +51,13 @@ HDDEDATA CALLBACK DdeInternal::CliCallback( UINT nCode, UINT nCbType, const DdeInstData& rInst = ImpGetInstData(); - for ( size_t i = 0; i < rAll.size(); ++i) + for ( DdeConnection* pConn : rAll ) { - self = rAll[i]; - - if ( self->pImp->hConv == hConv ) + if ( pConn->pImp->hConv == hConv ) + { + self = pConn; break; + } } if( self ) diff --git a/svtools/source/control/indexentryres.cxx b/svtools/source/control/indexentryres.cxx index 9420a37b278f..d0b52b39d797 100644 --- a/svtools/source/control/indexentryres.cxx +++ b/svtools/source/control/indexentryres.cxx @@ -49,9 +49,9 @@ const OUString& IndexEntryResource::GetTranslation(const OUString &r_Algorithm) aLocaleFreeAlgorithm = r_Algorithm.copy(nIndex); } - for (size_t i = 0; i < m_aData.size(); ++i) - if (aLocaleFreeAlgorithm == m_aData[i].GetAlgorithm()) - return m_aData[i].GetTranslation(); + for (const auto& rData : m_aData) + if (aLocaleFreeAlgorithm == rData.GetAlgorithm()) + return rData.GetTranslation(); return r_Algorithm; }