[Libreoffice-commits] core.git: 2 commits - basic/source include/sfx2 sfx2/source
Noel Grandin
noel.grandin at collabora.co.uk
Wed May 2 06:25:59 UTC 2018
basic/source/classes/image.cxx | 59 ++++++++++++++++++----------------------
basic/source/comp/codegen.cxx | 2 -
basic/source/inc/image.hxx | 10 +++---
include/sfx2/evntconf.hxx | 10 +++---
sfx2/source/config/evntconf.cxx | 13 +++-----
5 files changed, 43 insertions(+), 51 deletions(-)
New commits:
commit d90d9b422789b152416cc66f700a9af2d0a8285d
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Mon Apr 30 08:57:08 2018 +0200
loplugin:useuniqueptr in SfxEventNamesList
Change-Id: Ie296881069393001842f4424f398b0edefd89ac5
Reviewed-on: https://gerrit.libreoffice.org/53702
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/include/sfx2/evntconf.hxx b/include/sfx2/evntconf.hxx
index bf59d805a074..670b3ec6b558 100644
--- a/include/sfx2/evntconf.hxx
+++ b/include/sfx2/evntconf.hxx
@@ -27,6 +27,7 @@
#include <sfx2/event.hxx>
#include <sfx2/sfxsids.hrc>
#include <svl/macitem.hxx>
+#include <memory>
#include <vector>
class SfxObjectShell;
@@ -49,21 +50,20 @@ struct SFX2_DLLPUBLIC SfxEventName
class SFX2_DLLPUBLIC SfxEventNamesList
{
private:
- ::std::vector< SfxEventName* > aEventNamesList;
- void DelDtor();
+ ::std::vector< std::unique_ptr<SfxEventName> > aEventNamesList;
public:
SfxEventNamesList() {}
SfxEventNamesList( const SfxEventNamesList &rCpy ) { *this = rCpy; }
- ~SfxEventNamesList() { DelDtor(); }
+ ~SfxEventNamesList();
SfxEventNamesList& operator=( const SfxEventNamesList &rCpy );
size_t size() const { return aEventNamesList.size(); };
SfxEventName* at( size_t Index ) const
- { return Index < aEventNamesList.size() ? aEventNamesList[ Index ] : nullptr; }
+ { return Index < aEventNamesList.size() ? aEventNamesList[ Index ].get() : nullptr; }
- void push_back( SfxEventName* Item ) { aEventNamesList.push_back( Item ); }
+ void push_back( std::unique_ptr<SfxEventName> Item ) { aEventNamesList.push_back( std::move(Item) ); }
};
class SFX2_DLLPUBLIC SfxEventNamesItem : public SfxPoolItem
diff --git a/sfx2/source/config/evntconf.cxx b/sfx2/source/config/evntconf.cxx
index 6bf38484b62d..e612c6156fef 100644
--- a/sfx2/source/config/evntconf.cxx
+++ b/sfx2/source/config/evntconf.cxx
@@ -50,21 +50,18 @@ using namespace com::sun::star;
SfxEventNamesList& SfxEventNamesList::operator=( const SfxEventNamesList& rTbl )
{
- DelDtor();
+ aEventNamesList.clear();
for ( size_t i = 0, n = rTbl.size(); i < n; ++i )
{
SfxEventName* pTmp = rTbl.at( i );
- SfxEventName* pNew = new SfxEventName( *pTmp );
- aEventNamesList.push_back( pNew );
+ std::unique_ptr<SfxEventName> pNew(new SfxEventName( *pTmp ));
+ aEventNamesList.push_back( std::move(pNew) );
}
return *this;
}
-void SfxEventNamesList::DelDtor()
+SfxEventNamesList::~SfxEventNamesList()
{
- for (SfxEventName* i : aEventNamesList)
- delete i;
- aEventNamesList.clear();
}
bool SfxEventNamesItem::operator==( const SfxPoolItem& rAttr ) const
@@ -114,7 +111,7 @@ sal_uInt16 SfxEventNamesItem::GetVersion( sal_uInt16 ) const
void SfxEventNamesItem::AddEvent( const OUString& rName, const OUString& rUIName, SvMacroItemId nID )
{
- aEventsList.push_back( new SfxEventName( nID, rName, !rUIName.isEmpty() ? rUIName : rName ) );
+ aEventsList.push_back( std::unique_ptr<SfxEventName>(new SfxEventName( nID, rName, !rUIName.isEmpty() ? rUIName : rName )) );
}
commit 1cb646dc5fe56c614d2740cdc60d382f3d660b6b
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Sun Apr 29 18:40:45 2018 +0200
loplugin:useuniqueptr in SbiImage
Change-Id: I24ee5de3628d6436dc045cb543d35b16074ef189
Reviewed-on: https://gerrit.libreoffice.org/53700
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 34a6431c1876..7636a62d419c 100644
--- a/basic/source/classes/image.cxx
+++ b/basic/source/classes/image.cxx
@@ -53,9 +53,9 @@ SbiImage::~SbiImage()
void SbiImage::Clear()
{
mvStringOffsets.clear();
- delete[] pStrings;
- delete[] pCode;
- ReleaseLegacyBuffer();
+ pStrings.reset();
+ pCode.reset();
+ pLegacyPCode.reset();
pStrings = nullptr;
pCode = nullptr;
nFlags = SbiImageFlags::NONE;
@@ -160,18 +160,17 @@ bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion )
}
case FileOffset::PCode:
if( bBadVer ) break;
- pCode = new char[ nLen ];
+ pCode.reset(new char[ nLen ]);
nCodeSize = nLen;
- r.ReadBytes(pCode, nCodeSize);
+ r.ReadBytes(pCode.get(), nCodeSize);
if ( bLegacy )
{
- ReleaseLegacyBuffer(); // release any previously held buffer
nLegacyCodeSize = static_cast<sal_uInt16>(nCodeSize);
- pLegacyPCode = pCode;
+ pLegacyPCode = std::move(pCode);
- PCodeBuffConvertor< sal_uInt16, sal_uInt32 > aLegacyToNew( reinterpret_cast<sal_uInt8*>(pLegacyPCode), nLegacyCodeSize );
+ PCodeBuffConvertor< sal_uInt16, sal_uInt32 > aLegacyToNew( reinterpret_cast<sal_uInt8*>(pLegacyPCode.get()), nLegacyCodeSize );
aLegacyToNew.convert();
- pCode = reinterpret_cast<char*>(aLegacyToNew.GetBuffer());
+ pCode.reset(reinterpret_cast<char*>(aLegacyToNew.GetBuffer()));
nCodeSize = aLegacyToNew.GetSize();
// we don't release the legacy buffer
// right now, that's because the module
@@ -209,8 +208,7 @@ bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion )
r.ReadUInt32( nLen );
if( SbiGood( r ) )
{
- delete [] pStrings;
- pStrings = new sal_Unicode[ nLen ];
+ pStrings.reset(new sal_Unicode[ nLen ]);
nStringSize = static_cast<sal_uInt16>(nLen);
std::unique_ptr<char[]> pByteStrings(new char[ nLen ]);
@@ -219,7 +217,7 @@ bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion )
{
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 ) );
+ memcpy( pStrings.get() + nOff2, aStr.getStr(), (aStr.getLength() + 1) * sizeof( sal_Unicode ) );
}
}
break;
@@ -405,16 +403,15 @@ bool SbiImage::Save( SvStream& r, sal_uInt32 nVer )
nPos = SbiOpenRecord( r, FileOffset::PCode, 1 );
if ( bLegacy )
{
- ReleaseLegacyBuffer(); // release any previously held buffer
- PCodeBuffConvertor< sal_uInt32, sal_uInt16 > aNewToLegacy( reinterpret_cast<sal_uInt8*>(pCode), nCodeSize );
+ PCodeBuffConvertor< sal_uInt32, sal_uInt16 > aNewToLegacy( reinterpret_cast<sal_uInt8*>(pCode.get()), nCodeSize );
aNewToLegacy.convert();
- pLegacyPCode = reinterpret_cast<char*>(aNewToLegacy.GetBuffer());
+ pLegacyPCode.reset(reinterpret_cast<char*>(aNewToLegacy.GetBuffer()));
nLegacyCodeSize = aNewToLegacy.GetSize();
- r.WriteBytes(pLegacyPCode, nLegacyCodeSize);
+ r.WriteBytes(pLegacyPCode.get(), nLegacyCodeSize);
}
else
{
- r.WriteBytes(pCode, nCodeSize);
+ r.WriteBytes(pCode.get(), nCodeSize);
}
SbiCloseRecord( r, nPos );
}
@@ -433,7 +430,7 @@ bool SbiImage::Save( SvStream& r, sal_uInt32 nVer )
for( size_t i = 0; i < mvStringOffsets.size(); i++ )
{
sal_uInt16 nOff = static_cast<sal_uInt16>(mvStringOffsets[ i ]);
- OString aStr(OUStringToOString(OUString(pStrings + nOff), eCharSet));
+ OString aStr(OUStringToOString(OUString(pStrings.get() + nOff), eCharSet));
memcpy( pByteStrings.get() + nOff, aStr.getStr(), (aStr.getLength() + 1) * sizeof( char ) );
}
r.WriteUInt32( nStringSize );
@@ -534,10 +531,10 @@ void SbiImage::MakeStrings( short nSize )
nStringIdx = 0;
nStringOff = 0;
nStringSize = 1024;
- pStrings = new sal_Unicode[ nStringSize ];
+ pStrings.reset( new sal_Unicode[ nStringSize ]);
mvStringOffsets.resize(nSize);
memset( mvStringOffsets.data(), 0, nSize * sizeof( sal_uInt32 ) );
- memset( pStrings, 0, nStringSize * sizeof( sal_Unicode ) );
+ memset( pStrings.get(), 0, nStringSize * sizeof( sal_Unicode ) );
}
// Add a string to StringPool. The String buffer is dynamically
@@ -560,16 +557,15 @@ void SbiImage::AddString( const OUString& r )
{
sal_uInt32 nNewLen = needed + 1024;
nNewLen &= 0xFFFFFC00; // trim to 1K border
- sal_Unicode* p = new sal_Unicode[nNewLen];
- memcpy( p, pStrings, nStringSize * sizeof( sal_Unicode ) );
- delete[] pStrings;
- pStrings = p;
+ std::unique_ptr<sal_Unicode[]> p(new sal_Unicode[nNewLen]);
+ memcpy( p.get(), pStrings.get(), nStringSize * sizeof( sal_Unicode ) );
+ pStrings = std::move(p);
nStringSize = sal::static_int_cast< sal_uInt16 >(nNewLen);
}
if( !bError )
{
mvStringOffsets[ nStringIdx++ ] = nStringOff;
- memcpy( pStrings + nStringOff, r.getStr(), len * sizeof( sal_Unicode ) );
+ memcpy( pStrings.get() + nStringOff, r.getStr(), len * sizeof( sal_Unicode ) );
nStringOff = nStringOff + len;
// Last String? The update the size of the buffer
if( nStringIdx >= short(mvStringOffsets.size()) )
@@ -584,9 +580,9 @@ void SbiImage::AddString( const OUString& r )
// The block was fetched by the compiler from class SbBuffer and
// is already created with new. Additionally it contains all Integers
// in Big Endian format, so can be directly read/written.
-void SbiImage::AddCode( char* p, sal_uInt32 s )
+void SbiImage::AddCode( std::unique_ptr<char[]> p, sal_uInt32 s )
{
- pCode = p;
+ pCode = std::move(p);
nCodeSize = s;
}
@@ -616,7 +612,7 @@ OUString SbiImage::GetString( short nId ) const
if( nId && nId <= short(mvStringOffsets.size()) )
{
sal_uInt32 nOff = mvStringOffsets[ nId - 1 ];
- sal_Unicode* pStr = pStrings + nOff;
+ sal_Unicode* pStr = pStrings.get() + nOff;
// #i42467: Special treatment for vbNullChar
if( *pStr == 0 )
@@ -645,18 +641,17 @@ const SbxObject* SbiImage::FindType (const OUString& aTypeName) const
sal_uInt16 SbiImage::CalcLegacyOffset( sal_Int32 nOffset )
{
- return SbiCodeGen::calcLegacyOffSet( reinterpret_cast<sal_uInt8*>(pCode), nOffset ) ;
+ return SbiCodeGen::calcLegacyOffSet( reinterpret_cast<sal_uInt8*>(pCode.get()), nOffset ) ;
}
sal_uInt32 SbiImage::CalcNewOffset( sal_Int16 nOffset )
{
- return SbiCodeGen::calcNewOffSet( reinterpret_cast<sal_uInt8*>(pLegacyPCode), nOffset ) ;
+ return SbiCodeGen::calcNewOffSet( reinterpret_cast<sal_uInt8*>(pLegacyPCode.get()), nOffset ) ;
}
void SbiImage::ReleaseLegacyBuffer()
{
- delete[] pLegacyPCode;
- pLegacyPCode = nullptr;
+ pLegacyPCode.reset();
nLegacyCodeSize = 0;
}
diff --git a/basic/source/comp/codegen.cxx b/basic/source/comp/codegen.cxx
index bcab0d0a0f95..9e38c02a7cb9 100644
--- a/basic/source/comp/codegen.cxx
+++ b/basic/source/comp/codegen.cxx
@@ -350,7 +350,7 @@ void SbiCodeGen::Save()
}
}
// The code
- p->AddCode( aCode.GetBuffer(), aCode.GetSize() );
+ p->AddCode( std::unique_ptr<char[]>(aCode.GetBuffer()), aCode.GetSize() );
// The global StringPool. 0 is not occupied.
SbiStringPool* pPool = &pParser->aGblStrings;
diff --git a/basic/source/inc/image.hxx b/basic/source/inc/image.hxx
index f79e3c51c98a..f286e3e286fb 100644
--- a/basic/source/inc/image.hxx
+++ b/basic/source/inc/image.hxx
@@ -47,9 +47,9 @@ class SbiImage {
SbxArrayRef rTypes; // User defined types
SbxArrayRef rEnums; // Enum types
std::vector<sal_uInt32> mvStringOffsets; // StringId-Offsets
- sal_Unicode* pStrings; // StringPool
- char* pCode; // Code-Image
- char* pLegacyPCode; // Code-Image
+ std::unique_ptr<sal_Unicode[]> pStrings; // StringPool
+ std::unique_ptr<char[]> pCode; // Code-Image
+ std::unique_ptr<char[]> pLegacyPCode; // Code-Image
bool bError;
SbiImageFlags nFlags;
sal_uInt32 nStringSize;
@@ -63,7 +63,7 @@ class SbiImage {
// routines for the compiler:
void MakeStrings( short ); // establish StringPool
void AddString( const OUString& );
- void AddCode( char*, sal_uInt32 );
+ void AddCode( std::unique_ptr<char[]>, sal_uInt32 );
void AddType(SbxObject const *);
void AddEnum(SbxObject *);
@@ -83,7 +83,7 @@ public:
bool Save( SvStream&, sal_uInt32 = B_CURVERSION );
bool IsError() { return bError; }
- const char* GetCode() const { return pCode; }
+ const char* GetCode() const { return pCode.get(); }
sal_uInt32 GetCodeSize() const { return nCodeSize; }
sal_uInt16 GetBase() const { return nDimBase; }
OUString GetString( short nId ) const;
More information about the Libreoffice-commits
mailing list