tdf#147021 Use std::size() instead of SAL_N_ELEMENTS() macro

Also change some range based for.

Change-Id: I32c5cbe0033c40cde3f1fc86ec8af90e558f2652
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141666
Tested-by: Jenkins
Reviewed-by: Hossein <hossein@libreoffice.org>
This commit is contained in:
jsala
2022-06-25 13:35:01 +02:00
committed by Hossein
parent 804f21e42b
commit 04a58d7eae
9 changed files with 25 additions and 42 deletions

View File

@@ -130,7 +130,7 @@ void write8(osl::File & file, sal_uInt64 value) {
} }
unsigned char buf[1]; unsigned char buf[1];
buf[0] = value & 0xFF; buf[0] = value & 0xFF;
write(file, buf, SAL_N_ELEMENTS(buf)); write(file, buf, std::size(buf));
} }
void write16(osl::File & file, sal_uInt64 value) { void write16(osl::File & file, sal_uInt64 value) {
@@ -142,7 +142,7 @@ void write16(osl::File & file, sal_uInt64 value) {
unsigned char buf[2]; unsigned char buf[2];
buf[0] = value & 0xFF; buf[0] = value & 0xFF;
buf[1] = (value >> 8) & 0xFF; buf[1] = (value >> 8) & 0xFF;
write(file, buf, SAL_N_ELEMENTS(buf)); write(file, buf, std::size(buf));
} }
void write32(osl::File & file, sal_uInt64 value) { void write32(osl::File & file, sal_uInt64 value) {
@@ -156,7 +156,7 @@ void write32(osl::File & file, sal_uInt64 value) {
buf[1] = (value >> 8) & 0xFF; buf[1] = (value >> 8) & 0xFF;
buf[2] = (value >> 16) & 0xFF; buf[2] = (value >> 16) & 0xFF;
buf[3] = (value >> 24) & 0xFF; buf[3] = (value >> 24) & 0xFF;
write(file, buf, SAL_N_ELEMENTS(buf)); write(file, buf, std::size(buf));
} }
void write64(osl::File & file, sal_uInt64 value) { void write64(osl::File & file, sal_uInt64 value) {
@@ -169,7 +169,7 @@ void write64(osl::File & file, sal_uInt64 value) {
buf[5] = (value >> 40) & 0xFF; buf[5] = (value >> 40) & 0xFF;
buf[6] = (value >> 48) & 0xFF; buf[6] = (value >> 48) & 0xFF;
buf[7] = (value >> 56) & 0xFF; buf[7] = (value >> 56) & 0xFF;
write(file, buf, SAL_N_ELEMENTS(buf)); write(file, buf, std::size(buf));
} }
void writeIso60599Binary32(osl::File & file, float value) { void writeIso60599Binary32(osl::File & file, float value) {
@@ -182,7 +182,7 @@ void writeIso60599Binary32(osl::File & file, float value) {
std::swap(sa.buf[0], sa.buf[3]); std::swap(sa.buf[0], sa.buf[3]);
std::swap(sa.buf[1], sa.buf[2]); std::swap(sa.buf[1], sa.buf[2]);
#endif #endif
write(file, sa.buf, SAL_N_ELEMENTS(sa.buf)); write(file, sa.buf, std::size(sa.buf));
} }
void writeIso60599Binary64(osl::File & file, double value) { void writeIso60599Binary64(osl::File & file, double value) {
@@ -197,7 +197,7 @@ void writeIso60599Binary64(osl::File & file, double value) {
std::swap(sa.buf[2], sa.buf[5]); std::swap(sa.buf[2], sa.buf[5]);
std::swap(sa.buf[3], sa.buf[4]); std::swap(sa.buf[3], sa.buf[4]);
#endif #endif
write(file, sa.buf, SAL_N_ELEMENTS(sa.buf)); write(file, sa.buf, std::size(sa.buf));
} }
OString toAscii(OUString const & name) { OString toAscii(OUString const & name) {

View File

@@ -29,7 +29,7 @@ static void decode(const OUString& rIn, const OUString &rOut)
//mcrypt --bare -a arcfour -o hex -k 435645 -s 3 //mcrypt --bare -a arcfour -o hex -k 435645 -s 3
const sal_uInt8 aKey[3] = {'C', 'V', 'E'}; const sal_uInt8 aKey[3] = {'C', 'V', 'E'};
rtlCipherError result = rtl_cipher_init(cipher, rtl_Cipher_DirectionDecode, aKey, SAL_N_ELEMENTS(aKey), nullptr, 0); rtlCipherError result = rtl_cipher_init(cipher, rtl_Cipher_DirectionDecode, aKey, std::size(aKey), nullptr, 0);
CPPUNIT_ASSERT_EQUAL_MESSAGE("cipher init failed", rtl_Cipher_E_None, result); CPPUNIT_ASSERT_EQUAL_MESSAGE("cipher init failed", rtl_Cipher_E_None, result);

View File

@@ -29,7 +29,6 @@
#include <osl/process.h> #include <osl/process.h>
#include <osl/test/uniquepipename.hxx> #include <osl/test/uniquepipename.hxx>
#include <osl/time.h> #include <osl/time.h>
#include <sal/macros.h>
#include <unotest/getargument.hxx> #include <unotest/getargument.hxx>
#include <unotest/officeconnection.hxx> #include <unotest/officeconnection.hxx>
#include <unotest/toabsolutefileurl.hxx> #include <unotest/toabsolutefileurl.hxx>
@@ -81,7 +80,7 @@ void OfficeConnection::setUp() {
osl_executeProcess( osl_executeProcess(
toAbsoluteFileUrl( toAbsoluteFileUrl(
argSoffice.copy(RTL_CONSTASCII_LENGTH("path:"))).pData, argSoffice.copy(RTL_CONSTASCII_LENGTH("path:"))).pData,
args, SAL_N_ELEMENTS(args), 0, nullptr, nullptr, envs, envs == nullptr ? 0 : 1, args, std::size(args), 0, nullptr, nullptr, envs, envs == nullptr ? 0 : 1,
&process_)); &process_));
} else if (argSoffice.match("connect:")) { } else if (argSoffice.match("connect:")) {
desc = argSoffice.copy(RTL_CONSTASCII_LENGTH("connect:")); desc = argSoffice.copy(RTL_CONSTASCII_LENGTH("connect:"));

View File

@@ -96,7 +96,7 @@ OUString SvtCompatibilityEntry::getName( const Index rIdx )
}; };
/* Size of sPropertyName array not equal size of the SvtCompatibilityEntry::Index enum class */ /* Size of sPropertyName array not equal size of the SvtCompatibilityEntry::Index enum class */
assert( SAL_N_ELEMENTS(sPropertyName) == static_cast<int>( SvtCompatibilityEntry::getElementCount() ) ); assert( std::size(sPropertyName) == SvtCompatibilityEntry::getElementCount() );
return OUString::createFromAscii( sPropertyName[ static_cast<int>(rIdx) ] ); return OUString::createFromAscii( sPropertyName[ static_cast<int>(rIdx) ] );
} }

View File

@@ -32,7 +32,6 @@
#include <unotools/syslocale.hxx> #include <unotools/syslocale.hxx>
#include <rtl/ustrbuf.hxx> #include <rtl/ustrbuf.hxx>
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <sal/macros.h>
#include <sal/log.hxx> #include <sal/log.hxx>
#include <string.h> #include <string.h>
@@ -886,7 +885,7 @@ FontWeight FontSubstConfiguration::getSubstWeight( const css::uno::Reference< XN
{ {
if( !pLine->isEmpty() ) if( !pLine->isEmpty() )
{ {
for( weight=SAL_N_ELEMENTS(pWeightNames)-1; weight >= 0; weight-- ) for( weight=std::size(pWeightNames)-1; weight >= 0; weight-- )
if( pLine->equalsIgnoreAsciiCaseAscii( pWeightNames[weight].pName ) ) if( pLine->equalsIgnoreAsciiCaseAscii( pWeightNames[weight].pName ) )
break; break;
} }
@@ -913,7 +912,7 @@ FontWidth FontSubstConfiguration::getSubstWidth( const css::uno::Reference< XNam
{ {
if( !pLine->isEmpty() ) if( !pLine->isEmpty() )
{ {
for( width=SAL_N_ELEMENTS(pWidthNames)-1; width >= 0; width-- ) for( width=std::size(pWidthNames)-1; width >= 0; width-- )
if( pLine->equalsIgnoreAsciiCaseAscii( pWidthNames[width].pName ) ) if( pLine->equalsIgnoreAsciiCaseAscii( pWidthNames[width].pName ) )
break; break;
} }

View File

@@ -33,7 +33,6 @@
#include <unotools/configitem.hxx> #include <unotools/configitem.hxx>
#include <unotools/lingucfg.hxx> #include <unotools/lingucfg.hxx>
#include <unotools/linguprops.hxx> #include <unotools/linguprops.hxx>
#include <sal/macros.h>
#include <comphelper/getexpandeduri.hxx> #include <comphelper/getexpandeduri.hxx>
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <o3tl/string_view.hxx> #include <o3tl/string_view.hxx>
@@ -271,15 +270,12 @@ NamesToHdl const aNamesToHdl[] =
uno::Sequence< OUString > SvtLinguConfigItem::GetPropertyNames() uno::Sequence< OUString > SvtLinguConfigItem::GetPropertyNames()
{ {
uno::Sequence< OUString > aNames; uno::Sequence< OUString > aNames;
aNames.realloc(std::size(aNamesToHdl));
sal_Int32 nMax = SAL_N_ELEMENTS(aNamesToHdl);
aNames.realloc( nMax );
OUString *pNames = aNames.getArray(); OUString *pNames = aNames.getArray();
sal_Int32 nIdx = 0; sal_Int32 nIdx = 0;
for (sal_Int32 i = 0; i < nMax; ++i) for (auto const & nameToHdl: aNamesToHdl)
{ {
const char *pFullPropName = aNamesToHdl[i].pFullPropName; const char *pFullPropName = nameToHdl.pFullPropName;
if (pFullPropName) if (pFullPropName)
pNames[ nIdx++ ] = OUString::createFromAscii( pFullPropName ); pNames[ nIdx++ ] = OUString::createFromAscii( pFullPropName );
} }

View File

@@ -24,7 +24,6 @@
#include <unotools/configitem.hxx> #include <unotools/configitem.hxx>
#include <com/sun/star/uno/Sequence.hxx> #include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/uno/Any.h> #include <com/sun/star/uno/Any.h>
#include <sal/macros.h>
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <i18nutil/transliteration.hxx> #include <i18nutil/transliteration.hxx>
@@ -153,10 +152,9 @@ Sequence< OUString > SvtSearchOptions_Impl::GetPropertyNames()
"IsUseWildcard" // 29 "IsUseWildcard" // 29
}; };
const int nCount = SAL_N_ELEMENTS( aPropNames ); Sequence< OUString > aNames(std::size(aPropNames));
Sequence< OUString > aNames( nCount );
OUString* pNames = aNames.getArray(); OUString* pNames = aNames.getArray();
for (sal_Int32 i = 0; i < nCount; ++i) for (std::size_t i = 0; i < std::size(aPropNames); ++i)
pNames[i] = OUString::createFromAscii( aPropNames[i] ); pNames[i] = OUString::createFromAscii( aPropNames[i] );
return aNames; return aNames;

View File

@@ -23,7 +23,6 @@
#include <sal/log.hxx> #include <sal/log.hxx>
#include <unotools/fontcvt.hxx> #include <unotools/fontcvt.hxx>
#include <unotools/fontdefs.hxx> #include <unotools/fontdefs.hxx>
#include <sal/macros.h>
#include <cstddef> #include <cstddef>
#include <map> #include <map>
@@ -1163,11 +1162,8 @@ StarSymbolToMSMultiFontImpl::StarSymbolToMSMultiFontImpl()
//Reverse map from a given starsymbol char to exact matches in ms symbol //Reverse map from a given starsymbol char to exact matches in ms symbol
//fonts. //fonts.
int nEntries = SAL_N_ELEMENTS(aConservativeTable); for (auto const & r: aConservativeTable)
int i;
for (i = 0; i < nEntries; ++i)
{ {
const ConvertTable& r = aConservativeTable[i];
SymbolEntry aEntry; SymbolEntry aEntry;
aEntry.eFont = r.meFont; aEntry.eFont = r.meFont;
for (aEntry.cIndex = 0xFF; aEntry.cIndex >= 0x20; --aEntry.cIndex) for (aEntry.cIndex = 0xFF; aEntry.cIndex >= 0x20; --aEntry.cIndex)
@@ -1190,12 +1186,9 @@ StarSymbolToMSMultiFontImpl::StarSymbolToMSMultiFontImpl()
sizeof(aTNRExtraTab)) sizeof(aTNRExtraTab))
}; };
//Allow extra conversions that are not perfect, but "good enough" //Allow extra conversions that are not perfect, but "good enough"
nEntries = SAL_N_ELEMENTS(aAggressiveTable); for (auto const & r: aAggressiveTable)
for (i = 0; i < nEntries; ++i)
{ {
const ExtendedConvertTable& r = aAggressiveTable[i];
SymbolEntry aEntry; SymbolEntry aEntry;
aEntry.eFont = r.meFont; aEntry.eFont = r.meFont;
for (int j = r.mnSize / sizeof(r.mpTable[0]) - 1; j >=0; --j) for (int j = r.mnSize / sizeof(r.mpTable[0]) - 1; j >=0; --j)
@@ -1353,9 +1346,8 @@ const ConvertChar* ConvertChar::GetRecodeData( std::u16string_view rOrgFontName,
if( aMapName == "starsymbol" if( aMapName == "starsymbol"
|| aMapName == "opensymbol" ) || aMapName == "opensymbol" )
{ {
for( std::size_t i = 0; i < SAL_N_ELEMENTS(aStarSymbolRecodeTable); ++i) for (auto const & r: aStarSymbolRecodeTable)
{ {
const RecodeTable& r = aStarSymbolRecodeTable[i];
if( aOrgName.equalsAscii( r.pOrgName ) ) if( aOrgName.equalsAscii( r.pOrgName ) )
{ {
pCvt = &r.aCvt; pCvt = &r.aCvt;
@@ -1368,9 +1360,8 @@ const ConvertChar* ConvertChar::GetRecodeData( std::u16string_view rOrgFontName,
//adobe-symbol to unicode conversion in rtl instead //adobe-symbol to unicode conversion in rtl instead
else if( aMapName == "applesymbol" ) else if( aMapName == "applesymbol" )
{ {
for( std::size_t i = 0; i < SAL_N_ELEMENTS(aAppleSymbolRecodeTable); ++i) for (auto const & r: aAppleSymbolRecodeTable)
{ {
const RecodeTable& r = aAppleSymbolRecodeTable[i];
if( aOrgName.equalsAscii( r.pOrgName ) ) if( aOrgName.equalsAscii( r.pOrgName ) )
{ {
pCvt = &r.aCvt; pCvt = &r.aCvt;

View File

@@ -204,9 +204,9 @@ struct BasicTest : public test::BootstrapFixture
mxErrHandler.set( new ErrorHandler() ); mxErrHandler.set( new ErrorHandler() );
uno::Reference<XDocumentBuilder> xDB( getMultiServiceFactory()->createInstance("com.sun.star.xml.dom.DocumentBuilder"), uno::UNO_QUERY_THROW ); uno::Reference<XDocumentBuilder> xDB( getMultiServiceFactory()->createInstance("com.sun.star.xml.dom.DocumentBuilder"), uno::UNO_QUERY_THROW );
mxDomBuilder.set( xDB ); mxDomBuilder.set( xDB );
mxValidInStream.set( new SequenceInputStream(css::uno::Sequence<sal_Int8>(reinterpret_cast<sal_Int8 const *>(validTestFile), SAL_N_ELEMENTS(validTestFile))) ); mxValidInStream.set( new SequenceInputStream(css::uno::Sequence<sal_Int8>(reinterpret_cast<sal_Int8 const *>(validTestFile), std::size(validTestFile))) );
mxWarningInStream.set( new SequenceInputStream(css::uno::Sequence<sal_Int8>(reinterpret_cast<sal_Int8 const *>(warningTestFile), SAL_N_ELEMENTS(warningTestFile))) ); mxWarningInStream.set( new SequenceInputStream(css::uno::Sequence<sal_Int8>(reinterpret_cast<sal_Int8 const *>(warningTestFile), std::size(warningTestFile))) );
mxErrorInStream.set( new SequenceInputStream(css::uno::Sequence<sal_Int8>(reinterpret_cast<sal_Int8 const *>(errorTestFile), SAL_N_ELEMENTS(errorTestFile))) ); mxErrorInStream.set( new SequenceInputStream(css::uno::Sequence<sal_Int8>(reinterpret_cast<sal_Int8 const *>(errorTestFile), std::size(errorTestFile))) );
mxDomBuilder->setErrorHandler(mxErrHandler); mxDomBuilder->setErrorHandler(mxErrHandler);
} }
@@ -288,7 +288,7 @@ struct SerializerTest : public test::BootstrapFixture
mxErrHandler.set( new ErrorHandler() ); mxErrHandler.set( new ErrorHandler() );
uno::Reference<XDocumentBuilder> xDB( getMultiServiceFactory()->createInstance("com.sun.star.xml.dom.DocumentBuilder"), uno::UNO_QUERY_THROW ); uno::Reference<XDocumentBuilder> xDB( getMultiServiceFactory()->createInstance("com.sun.star.xml.dom.DocumentBuilder"), uno::UNO_QUERY_THROW );
mxDomBuilder.set( xDB ); mxDomBuilder.set( xDB );
mxInStream.set( new SequenceInputStream(css::uno::Sequence<sal_Int8>(reinterpret_cast<sal_Int8 const *>(validTestFile), SAL_N_ELEMENTS(validTestFile))) ); mxInStream.set( new SequenceInputStream(css::uno::Sequence<sal_Int8>(reinterpret_cast<sal_Int8 const *>(validTestFile), std::size(validTestFile))) );
mxDomBuilder->setErrorHandler(mxErrHandler); mxDomBuilder->setErrorHandler(mxErrHandler);
mxHandler.set( new DocumentHandler ); mxHandler.set( new DocumentHandler );
mxTokHandler.set( new TokenHandler ); mxTokHandler.set( new TokenHandler );