[Libreoffice-commits] core.git: 2 commits - basic/source i18npool/inc i18npool/source

Noel Grandin noel.grandin at collabora.co.uk
Sun Apr 29 16:22:45 UTC 2018


 basic/source/classes/image.cxx                                    |   47 ++++------
 basic/source/inc/image.hxx                                        |    3 
 i18npool/inc/cclass_unicode.hxx                                   |    6 -
 i18npool/source/characterclassification/cclass_unicode_parser.cxx |   23 +---
 4 files changed, 32 insertions(+), 47 deletions(-)

New commits:
commit 2c1f77d34e5a660a72170e30986bd77d9b965ca1
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Apr 26 11:37:45 2018 +0200

    loplugin:useuniqueptr in cclass_Unicode
    
    Change-Id: Iecfff4104ef19f9bc6f83a403d99aecb2eda2514
    Reviewed-on: https://gerrit.libreoffice.org/53607
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/i18npool/inc/cclass_unicode.hxx b/i18npool/inc/cclass_unicode.hxx
index 2b6e3d9e890f..d962a3216585 100644
--- a/i18npool/inc/cclass_unicode.hxx
+++ b/i18npool/inc/cclass_unicode.hxx
@@ -131,9 +131,9 @@ private:
     css::uno::Reference < css::i18n::XNativeNumberSupplier > xNatNumSup;
     OUString             aStartChars;
     OUString             aContChars;
-    ParserFlags*         pTable;
-    ParserFlags*         pStart;
-    ParserFlags*         pCont;
+    std::unique_ptr<ParserFlags[]> pTable;
+    std::unique_ptr<ParserFlags[]> pStart;
+    std::unique_ptr<ParserFlags[]> pCont;
     sal_Int32            nStartTypes;
     sal_Int32            nContTypes;
     ScanState            eState;
diff --git a/i18npool/source/characterclassification/cclass_unicode_parser.cxx b/i18npool/source/characterclassification/cclass_unicode_parser.cxx
index 981912b53c07..a5cb1b680984 100644
--- a/i18npool/source/characterclassification/cclass_unicode_parser.cxx
+++ b/i18npool/source/characterclassification/cclass_unicode_parser.cxx
@@ -410,18 +410,16 @@ void cclass_Unicode::initParserTable( const Locale& rLocale, sal_Int32 startChar
     setupInternational( rLocale );
     // Memory of pTable is reused.
     if ( !pTable )
-        pTable = new ParserFlags[nDefCnt];
-    memcpy( pTable, pDefaultParserTable, sizeof(ParserFlags) * nDefCnt );
+        pTable.reset(new ParserFlags[nDefCnt]);
+    memcpy( pTable.get(), pDefaultParserTable, sizeof(ParserFlags) * nDefCnt );
     // Start and cont tables only need reallocation if different length.
     if ( pStart && userDefinedCharactersStart.getLength() != aStartChars.getLength() )
     {
-        delete [] pStart;
-        pStart = nullptr;
+        pStart.reset();
     }
     if ( pCont && userDefinedCharactersCont.getLength() != aContChars.getLength() )
     {
-        delete [] pCont;
-        pCont = nullptr;
+        pCont.reset();
     }
     nStartTypes = startCharTokenType;
     nContTypes = contCharTokenType;
@@ -515,7 +513,7 @@ void cclass_Unicode::initParserTable( const Locale& rLocale, sal_Int32 startChar
     if ( nLen )
     {
         if ( !pStart )
-            pStart = new ParserFlags[ nLen ];
+            pStart.reset(new ParserFlags[ nLen ]);
         const sal_Unicode* p = aStartChars.getStr();
         for ( sal_Int32 j=0; j<nLen; j++, p++ )
         {
@@ -529,7 +527,7 @@ void cclass_Unicode::initParserTable( const Locale& rLocale, sal_Int32 startChar
     if ( nLen )
     {
         if ( !pCont )
-            pCont = new ParserFlags[ nLen ];
+            pCont.reset(new ParserFlags[ nLen ]);
         const sal_Unicode* p = aContChars.getStr();
         for ( sal_Int32 j=0; j<nLen; j++ )
         {
@@ -543,12 +541,9 @@ void cclass_Unicode::initParserTable( const Locale& rLocale, sal_Int32 startChar
 
 void cclass_Unicode::destroyParserTable()
 {
-    if ( pCont )
-        delete [] pCont;
-    if ( pStart )
-        delete [] pStart;
-    if ( pTable )
-        delete [] pTable;
+    pCont.reset();
+    pStart.reset();
+    pTable.reset();
 }
 
 
commit fcd589d4f304daadb9ddc5308c577e5a789c1293
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Wed Apr 25 14:51:38 2018 +0200

    loplugin:useuniqueptr pStringOff in SbiImage
    
    Change-Id: I05de3e910bf857e095c99cade6fec22ccb2dd99d
    Reviewed-on: https://gerrit.libreoffice.org/53606
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/basic/source/classes/image.cxx b/basic/source/classes/image.cxx
index 9a26496db45b..34a6431c1876 100644
--- a/basic/source/classes/image.cxx
+++ b/basic/source/classes/image.cxx
@@ -29,12 +29,10 @@
 
 SbiImage::SbiImage()
 {
-    pStringOff = nullptr;
     pStrings   = nullptr;
     pCode      = nullptr;
     pLegacyPCode = nullptr;
     nFlags     = SbiImageFlags::NONE;
-    nStrings   = 0;
     nStringSize= 0;
     nCodeSize  = 0;
     nLegacyCodeSize  =
@@ -54,15 +52,13 @@ SbiImage::~SbiImage()
 
 void SbiImage::Clear()
 {
-    delete[] pStringOff;
+    mvStringOffsets.clear();
     delete[] pStrings;
     delete[] pCode;
     ReleaseLegacyBuffer();
-    pStringOff = nullptr;
     pStrings   = nullptr;
     pCode      = nullptr;
     nFlags     = SbiImageFlags::NONE;
-    nStrings   = 0;
     nStringSize= 0;
     nLegacyCodeSize  = 0;
     nCodeSize  = 0;
@@ -205,11 +201,10 @@ bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion )
                     nCount = nMaxStrings;
                 }
                 MakeStrings( nCount );
-                short i;
-                for( i = 0; i < nStrings && SbiGood( r ); i++ )
+                for( size_t i = 0; i < mvStringOffsets.size() && SbiGood( r ); i++ )
                 {
                     r.ReadUInt32( nOff );
-                    pStringOff[ i ] = static_cast<sal_uInt16>(nOff);
+                    mvStringOffsets[ i ] = static_cast<sal_uInt16>(nOff);
                 }
                 r.ReadUInt32( nLen );
                 if( SbiGood( r ) )
@@ -220,9 +215,9 @@ bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion )
 
                     std::unique_ptr<char[]> pByteStrings(new char[ nLen ]);
                     r.ReadBytes(pByteStrings.get(), nStringSize);
-                    for( short j = 0; j < nStrings; j++ )
+                    for( size_t j = 0; j < mvStringOffsets.size(); j++ )
                     {
-                        sal_uInt16 nOff2 = static_cast<sal_uInt16>(pStringOff[ j ]);
+                        sal_uInt16 nOff2 = static_cast<sal_uInt16>(mvStringOffsets[ j ]);
                         OUString aStr( pByteStrings.get() + nOff2, strlen(pByteStrings.get() + nOff2), eCharSet );
                         memcpy( pStrings + nOff2, aStr.getStr(), (aStr.getLength() + 1) * sizeof( sal_Unicode ) );
                     }
@@ -424,22 +419,20 @@ bool SbiImage::Save( SvStream& r, sal_uInt32 nVer )
         SbiCloseRecord( r, nPos );
     }
     // String-Pool?
-    if( nStrings )
+    if( !mvStringOffsets.empty() )
     {
-        nPos = SbiOpenRecord( r, FileOffset::StringPool, nStrings );
+        nPos = SbiOpenRecord( r, FileOffset::StringPool, mvStringOffsets.size() );
         // For every String:
         //  sal_uInt32 Offset of the Strings in the Stringblock
-        short i;
-
-        for( i = 0; i < nStrings && SbiGood( r ); i++ )
+        for( size_t i = 0; i < mvStringOffsets.size() && SbiGood( r ); i++ )
         {
-            r.WriteUInt32( pStringOff[ i ] );
+            r.WriteUInt32( mvStringOffsets[ i ] );
         }
         // Then the String-Block
         std::unique_ptr<char[]> pByteStrings(new char[ nStringSize ]);
-        for( i = 0; i < nStrings; i++ )
+        for( size_t i = 0; i < mvStringOffsets.size(); i++ )
         {
-            sal_uInt16 nOff = static_cast<sal_uInt16>(pStringOff[ i ]);
+            sal_uInt16 nOff = static_cast<sal_uInt16>(mvStringOffsets[ i ]);
             OString aStr(OUStringToOString(OUString(pStrings + nOff), eCharSet));
             memcpy( pByteStrings.get() + nOff, aStr.getStr(), (aStr.getLength() + 1) * sizeof( char ) );
         }
@@ -538,14 +531,12 @@ bool SbiImage::Save( SvStream& r, sal_uInt32 nVer )
 
 void SbiImage::MakeStrings( short nSize )
 {
-    nStrings = 0;
     nStringIdx = 0;
     nStringOff = 0;
     nStringSize = 1024;
     pStrings = new sal_Unicode[ nStringSize ];
-    pStringOff = new sal_uInt32[ nSize ];
-    nStrings = nSize;
-    memset( pStringOff, 0, nSize * sizeof( sal_uInt32 ) );
+    mvStringOffsets.resize(nSize);
+    memset( mvStringOffsets.data(), 0, nSize * sizeof( sal_uInt32 ) );
     memset( pStrings, 0, nStringSize * sizeof( sal_Unicode ) );
 }
 
@@ -553,7 +544,7 @@ void SbiImage::MakeStrings( short nSize )
 // growing in 1K-Steps
 void SbiImage::AddString( const OUString& r )
 {
-    if( nStringIdx >= nStrings )
+    if( nStringIdx >= short(mvStringOffsets.size()) )
     {
         bError = true;
     }
@@ -577,11 +568,11 @@ void SbiImage::AddString( const OUString& r )
         }
         if( !bError )
         {
-            pStringOff[ nStringIdx++ ] = nStringOff;
+            mvStringOffsets[ nStringIdx++ ] = nStringOff;
             memcpy( pStrings + nStringOff, r.getStr(), len * sizeof( sal_Unicode ) );
             nStringOff = nStringOff + len;
             // Last String? The update the size of the buffer
-            if( nStringIdx >= nStrings )
+            if( nStringIdx >= short(mvStringOffsets.size()) )
             {
                 nStringSize = nStringOff;
             }
@@ -622,15 +613,15 @@ void SbiImage::AddEnum(SbxObject* pObject) // Register enum type
 // Note: IDs start with 1
 OUString SbiImage::GetString( short nId ) const
 {
-    if( nId && nId <= nStrings )
+    if( nId && nId <= short(mvStringOffsets.size()) )
     {
-        sal_uInt32 nOff = pStringOff[ nId - 1 ];
+        sal_uInt32 nOff = mvStringOffsets[ nId - 1 ];
         sal_Unicode* pStr = pStrings + nOff;
 
         // #i42467: Special treatment for vbNullChar
         if( *pStr == 0 )
         {
-            sal_uInt32 nNextOff = (nId < nStrings) ? pStringOff[ nId ] : nStringOff;
+            sal_uInt32 nNextOff = (nId < short(mvStringOffsets.size())) ? mvStringOffsets[ nId ] : nStringOff;
             sal_uInt32 nLen = nNextOff - nOff - 1;
             if( nLen == 1 )
             {
diff --git a/basic/source/inc/image.hxx b/basic/source/inc/image.hxx
index 404e411c8fe0..f79e3c51c98a 100644
--- a/basic/source/inc/image.hxx
+++ b/basic/source/inc/image.hxx
@@ -46,13 +46,12 @@ class SbiImage {
 
     SbxArrayRef    rTypes;          // User defined types
     SbxArrayRef    rEnums;          // Enum types
-    sal_uInt32*    pStringOff;      // StringId-Offsets
+    std::vector<sal_uInt32>  mvStringOffsets; // StringId-Offsets
     sal_Unicode*   pStrings;        // StringPool
     char*          pCode;           // Code-Image
     char*          pLegacyPCode;        // Code-Image
     bool           bError;
     SbiImageFlags  nFlags;
-    short          nStrings;
     sal_uInt32     nStringSize;
     sal_uInt32     nCodeSize;
     sal_uInt16     nLegacyCodeSize;


More information about the Libreoffice-commits mailing list