tdf#147021: Use std::size() instead of SAL_N_ELEMENTS in several modules

Verified: make Library_tk Library_lng CppunitTest_sax_xmlimport Library_PresentationMinimizer Executable_xpdfimport
Change-Id: I1b7c30fda2b72cdc3fe1cf6bf802f15624aee148
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204771
Tested-by: Jenkins
Reviewed-by: Jonathan Clark <jonathan@libreoffice.org>
This commit is contained in:
Muhammad Naeem
2026-05-11 15:31:06 +02:00
committed by Jonathan Clark
parent 098e175fb5
commit 884db13b71
7 changed files with 16 additions and 10 deletions
+2 -1
View File
@@ -18,6 +18,7 @@
*/ */
#include <iterator>
#include <sal/macros.h> #include <sal/macros.h>
#include "lngopt.hxx" #include "lngopt.hxx"
#include <linguistic/misc.hxx> #include <linguistic/misc.hxx>
@@ -125,7 +126,7 @@ OUString LinguOptions::GetName( sal_Int32 nWID )
OUString aRes; OUString aRes;
if (0 <= nWID && o3tl::make_unsigned(nWID) < SAL_N_ELEMENTS(aWID_Name) if (0 <= nWID && o3tl::make_unsigned(nWID) < std::size(aWID_Name)
&& aWID_Name[ nWID ].nWID == nWID) && aWID_Name[ nWID ].nWID == nWID)
aRes = aWID_Name[nWID].aPropertyName; aRes = aWID_Name[nWID].aPropertyName;
else else
+2 -1
View File
@@ -18,6 +18,7 @@
*/ */
#include <iterator>
#include <sal/macros.h> #include <sal/macros.h>
#include "linguistic/misc.hxx" #include "linguistic/misc.hxx"
@@ -175,7 +176,7 @@ static const char *aSP[] =
PropertyHelper_Spell::PropertyHelper_Spell( PropertyHelper_Spell::PropertyHelper_Spell(
const Reference< XInterface > & rxSource, const Reference< XInterface > & rxSource,
Reference< XPropertySet > &rxPropSet ) : Reference< XPropertySet > &rxPropSet ) :
PropertyChgHelper ( rxSource, rxPropSet, aSP, SAL_N_ELEMENTS(aSP) ) PropertyChgHelper ( rxSource, rxPropSet, aSP, static_cast<sal_uInt16>(std::size(aSP)) )
{ {
SetDefault(); SetDefault();
sal_Int32 nLen = GetPropNames().getLength(); sal_Int32 nLen = GetPropNames().getLength();
+2 -1
View File
@@ -38,6 +38,7 @@
#include <unotools/ucbstreamhelper.hxx> #include <unotools/ucbstreamhelper.hxx>
#include <unotools/streamwrap.hxx> #include <unotools/streamwrap.hxx>
#include <sax/fastattribs.hxx> #include <sax/fastattribs.hxx>
#include <iterator>
#include <stack> #include <stack>
#include <string_view> #include <string_view>
#include <deque> #include <deque>
@@ -360,7 +361,7 @@ void XMLImportTest::setUp()
uno::UNO_QUERY_THROW); uno::UNO_QUERY_THROW);
xInit->initialize({ uno::Any(xTokenHandler) }); xInit->initialize({ uno::Any(xTokenHandler) });
sal_Int32 nNamespaceCount = SAL_N_ELEMENTS(DummyTokenHandler::namespaceURIs); sal_Int32 nNamespaceCount = static_cast<sal_Int32>(std::size(DummyTokenHandler::namespaceURIs));
uno::Sequence<uno::Any> namespaceArgs( nNamespaceCount + 1 ); uno::Sequence<uno::Any> namespaceArgs( nNamespaceCount + 1 );
auto p_namespaceArgs = namespaceArgs.getArray(); auto p_namespaceArgs = namespaceArgs.getArray();
p_namespaceArgs[0] <<= u"registerNamespaces"_ustr; p_namespaceArgs[0] <<= u"registerNamespaces"_ustr;
@@ -26,7 +26,7 @@
#include <com/sun/star/lang/XSingleServiceFactory.hpp> #include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <comphelper/propertysequence.hxx> #include <comphelper/propertysequence.hxx>
#include <comphelper/propertyvalue.hxx> #include <comphelper/propertyvalue.hxx>
#include <sal/macros.h> #include <iterator>
#include <sal/log.hxx> #include <sal/log.hxx>
#include <comphelper/diagnose_ex.hxx> #include <comphelper/diagnose_ex.hxx>
@@ -116,7 +116,7 @@ void OptimizerSettings::SaveSettingsToConfiguration( const Reference< XNameRepla
// Any( maFilterName ), // Any( maFilterName ),
Any( mbOpenNewDocument ) }; Any( mbOpenNewDocument ) };
for ( int i = 0; i < int(SAL_N_ELEMENTS( pNames )); i++ ) for ( int i = 0; i < static_cast<int>(std::size( pNames )); i++ )
{ {
try try
{ {
@@ -18,7 +18,7 @@
*/ */
#include "pnghelper.hxx" #include "pnghelper.hxx"
#include <sal/macros.h> #include <iterator>
#include <zlib.h> #include <zlib.h>
@@ -119,7 +119,7 @@ void PngHelper::appendFileHeader( OutputBuffer& o_rOutputBuf )
{ {
static const unsigned char aHeader[] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a }; static const unsigned char aHeader[] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
o_rOutputBuf.insert( o_rOutputBuf.end(), aHeader, aHeader + SAL_N_ELEMENTS(aHeader) ); o_rOutputBuf.insert( o_rOutputBuf.end(), aHeader, aHeader + std::size(aHeader) );
} }
size_t PngHelper::startChunk( const char* pChunkName, OutputBuffer& o_rOutputBuf ) size_t PngHelper::startChunk( const char* pChunkName, OutputBuffer& o_rOutputBuf )
+3 -1
View File
@@ -17,6 +17,8 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include <iterator>
#include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/uno/XComponentContext.hpp>
#include <controls/animatedimages.hxx> #include <controls/animatedimages.hxx>
#include <comphelper/diagnose_ex.hxx> #include <comphelper/diagnose_ex.hxx>
@@ -62,7 +64,7 @@ protected:
{ {
Throbber::ImageSet::N16px, Throbber::ImageSet::N32px, Throbber::ImageSet::N64px Throbber::ImageSet::N16px, Throbber::ImageSet::N32px, Throbber::ImageSet::N64px
}; };
for ( size_t i=0; i < SAL_N_ELEMENTS(aImageSets); ++i ) for ( size_t i=0; i < std::size(aImageSets); ++i )
{ {
const ::std::vector< OUString > aDefaultURLs( Throbber::getDefaultImageURLs( aImageSets[i] ) ); const ::std::vector< OUString > aDefaultURLs( Throbber::getDefaultImageURLs( aImageSets[i] ) );
const Sequence< OUString > aImageURLs( aDefaultURLs.data(), aDefaultURLs.size() ); const Sequence< OUString > aImageURLs( aDefaultURLs.data(), aDefaultURLs.size() );
+3 -2
View File
@@ -20,6 +20,7 @@
#include "sal/macros.h" #include "sal/macros.h"
#include <cstddef> #include <cstddef>
#include <iterator>
#include <memory> #include <memory>
#include "com/sun/star/beans/Introspection.hpp" #include "com/sun/star/beans/Introspection.hpp"
@@ -120,7 +121,7 @@ private:
"com.sun.star.script.InvocationAdapterFactory", "com.sun.star.script.InvocationAdapterFactory",
"com.sun.star.uri.UriSchemeParser_vndDOTsunDOTstarDOTscript" "com.sun.star.uri.UriSchemeParser_vndDOTsunDOTstarDOTscript"
}; };
for (::std::size_t i = 0; i < SAL_N_ELEMENTS(services); ++i) { for (::std::size_t i = 0; i < std::size(services); ++i) {
::rtl::OUString name(::rtl::OUString::createFromAscii(services[i])); ::rtl::OUString name(::rtl::OUString::createFromAscii(services[i]));
css::uno::Reference< css::uno::XInterface > instance; css::uno::Reference< css::uno::XInterface > instance;
try { try {
@@ -165,7 +166,7 @@ private:
static char const * const singletons[] = { static char const * const singletons[] = {
"com.sun.star.reflection.theTypeDescriptionManager" "com.sun.star.reflection.theTypeDescriptionManager"
}; };
for (std::size_t i = 0; i != SAL_N_ELEMENTS(singletons); ++i) { for (std::size_t i = 0; i != std::size(singletons); ++i) {
css::uno::Reference< css::uno::XInterface > instance( css::uno::Reference< css::uno::XInterface > instance(
context_->getValueByName( context_->getValueByName(
"/singletons/" + rtl::OUString::createFromAscii(singletons[i])), "/singletons/" + rtl::OUString::createFromAscii(singletons[i])),