[Libreoffice-commits] core.git: 2 commits - sc/inc sc/source sd/source
Noel Grandin
noel.grandin at collabora.co.uk
Wed Jun 27 06:32:42 UTC 2018
sc/inc/sheetevents.hxx | 4 +++-
sc/source/core/data/sheetevents.cxx | 30 +++++++++++-------------------
sd/source/filter/eppt/epptso.cxx | 2 +-
sd/source/filter/eppt/pptx-text.cxx | 22 +++++++++-------------
sd/source/filter/eppt/text.hxx | 4 ++--
5 files changed, 26 insertions(+), 36 deletions(-)
New commits:
commit 20dfe973a8c1ef0d873aca735711e288734c5cba
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Mon Jun 25 17:08:28 2018 +0200
loplugin:useuniqueptr in PortionObj
Change-Id: I79fcbaa12def04aa36bdf1928638b70ad490448c
Reviewed-on: https://gerrit.libreoffice.org/56494
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/sd/source/filter/eppt/epptso.cxx b/sd/source/filter/eppt/epptso.cxx
index 4ebeafe3c48e..69d520e7b742 100644
--- a/sd/source/filter/eppt/epptso.cxx
+++ b/sd/source/filter/eppt/epptso.cxx
@@ -1108,7 +1108,7 @@ void PPTWriter::ImplWriteTextStyleAtom( SvStream& rOut, int nTextInstance, sal_u
const PortionObj& rPortion = *(*it).get();
if ( rPortion.mpFieldEntry )
{
- const FieldEntry* pFieldEntry = rPortion.mpFieldEntry;
+ const FieldEntry* pFieldEntry = rPortion.mpFieldEntry.get();
switch ( pFieldEntry->nFieldType >> 28 )
{
diff --git a/sd/source/filter/eppt/pptx-text.cxx b/sd/source/filter/eppt/pptx-text.cxx
index 90011a09be3d..00e8c483c327 100644
--- a/sd/source/filter/eppt/pptx-text.cxx
+++ b/sd/source/filter/eppt/pptx-text.cxx
@@ -120,7 +120,7 @@ PortionObj::PortionObj(css::uno::Reference< css::text::XTextRange > & rXTextRang
nFieldType = ImplGetTextField( rXTextRange, mXPropSet, aURL );
if ( nFieldType )
{
- mpFieldEntry = new FieldEntry( nFieldType, 0, mnTextSize );
+ mpFieldEntry.reset( new FieldEntry( nFieldType, 0, mnTextSize ) );
if ( nFieldType >> 28 == 4 )
{
mpFieldEntry->aRepresentation = aString;
@@ -141,7 +141,7 @@ PortionObj::PortionObj(css::uno::Reference< css::text::XTextRange > & rXTextRang
mnTextSize = 1;
if ( bLast )
mnTextSize++;
- mpText = new sal_uInt16[ mnTextSize ];
+ mpText.reset( new sal_uInt16[ mnTextSize ] );
mpText[ 0 ] = 0x2a;
}
else
@@ -155,7 +155,7 @@ PortionObj::PortionObj(css::uno::Reference< css::text::XTextRange > & rXTextRang
mnTextSize++;
bRTL_endingParen = true;
}
- mpText = new sal_uInt16[ mnTextSize ];
+ mpText.reset( new sal_uInt16[ mnTextSize ] );
sal_uInt16 nChar;
for ( sal_Int32 i = 0; i < aString.getLength(); i++ )
{
@@ -261,7 +261,7 @@ void PortionObj::ImplGetPortionValues( FontCollection& rFontCollection, bool bGe
sal_Int16 nScriptType = SvtLanguageOptions::FromSvtScriptTypeToI18N( SvtLanguageOptions::GetScriptTypeOfLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() ) );
if ( mpText && mnTextSize && xPPTBreakIter.is() )
{
- OUString sT( reinterpret_cast<sal_Unicode *>(mpText), mnTextSize );
+ OUString sT( reinterpret_cast<sal_Unicode *>(mpText.get()), mnTextSize );
nScriptType = xPPTBreakIter->getScriptType( sT, 0 );
}
if ( nScriptType != css::i18n::ScriptType::COMPLEX )
@@ -440,8 +440,8 @@ void PortionObj::ImplGetPortionValues( FontCollection& rFontCollection, bool bGe
void PortionObj::ImplClear()
{
- delete mpFieldEntry;
- delete[] mpText;
+ mpFieldEntry.reset();
+ mpText.reset();
}
void PortionObj::ImplConstruct( const PortionObj& rPortionObj )
@@ -465,16 +465,12 @@ void PortionObj::ImplConstruct( const PortionObj& rPortionObj )
if ( rPortionObj.mpText )
{
- mpText = new sal_uInt16[ mnTextSize ];
- memcpy( mpText, rPortionObj.mpText, mnTextSize << 1 );
+ mpText.reset( new sal_uInt16[ mnTextSize ] );
+ memcpy( mpText.get(), rPortionObj.mpText.get(), mnTextSize << 1 );
}
- else
- mpText = nullptr;
if ( rPortionObj.mpFieldEntry )
- mpFieldEntry = new FieldEntry( *( rPortionObj.mpFieldEntry ) );
- else
- mpFieldEntry = nullptr;
+ mpFieldEntry.reset( new FieldEntry( *( rPortionObj.mpFieldEntry ) ) );
}
sal_uInt32 PortionObj::ImplCalculateTextPositions( sal_uInt32 nCurrentTextPosition )
diff --git a/sd/source/filter/eppt/text.hxx b/sd/source/filter/eppt/text.hxx
index d9e40f2ac91d..0928e9b72dba 100644
--- a/sd/source/filter/eppt/text.hxx
+++ b/sd/source/filter/eppt/text.hxx
@@ -144,8 +144,8 @@ class PortionObj final : public PropStateValue
sal_uInt32 mnTextSize;
bool mbLastPortion;
- sal_uInt16* mpText;
- FieldEntry* mpFieldEntry;
+ std::unique_ptr<sal_uInt16[]> mpText;
+ std::unique_ptr<FieldEntry> mpFieldEntry;
PortionObj( css::uno::Reference< css::text::XTextRange > & rXTextRangeRef,
bool bLast, FontCollection& rFontCollection );
commit 5be0637827cd987b7b7dda7ca2c54a3548d9ef51
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Mon Jun 25 16:46:32 2018 +0200
loplugin:useuniqueptr in ScSheetEvents
Change-Id: I7dce11ddf85fc92d6ac69ea307c4c1c181521460
Reviewed-on: https://gerrit.libreoffice.org/56492
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/sc/inc/sheetevents.hxx b/sc/inc/sheetevents.hxx
index 267e442f25a3..8434cc209e4c 100644
--- a/sc/inc/sheetevents.hxx
+++ b/sc/inc/sheetevents.hxx
@@ -21,6 +21,8 @@
#define INCLUDED_SC_INC_SHEETEVENTS_HXX
#include <rtl/ustring.hxx>
+#include <memory>
+#include <boost/optional.hpp>
enum class ScSheetEventId {
FOCUS, UNFOCUS, SELECT, DOUBLECLICK, RIGHTCLICK, CHANGE, CALCULATE, COUNT,
@@ -29,7 +31,7 @@ enum class ScSheetEventId {
class ScSheetEvents
{
- OUString** mpScriptNames;
+ std::unique_ptr<boost::optional<OUString>[]> mpScriptNames;
void Clear();
diff --git a/sc/source/core/data/sheetevents.cxx b/sc/source/core/data/sheetevents.cxx
index 0cf3be3de55d..b8f0430e2101 100644
--- a/sc/source/core/data/sheetevents.cxx
+++ b/sc/source/core/data/sheetevents.cxx
@@ -73,13 +73,7 @@ ScSheetEvents::~ScSheetEvents()
void ScSheetEvents::Clear()
{
- if (mpScriptNames)
- {
- for (sal_Int32 nEvent=0; nEvent<COUNT; ++nEvent)
- delete mpScriptNames[nEvent];
- delete[] mpScriptNames;
- mpScriptNames = nullptr;
- }
+ mpScriptNames.reset();
}
ScSheetEvents::ScSheetEvents(const ScSheetEvents& rOther) :
@@ -93,12 +87,9 @@ ScSheetEvents& ScSheetEvents::operator=(const ScSheetEvents& rOther)
Clear();
if (rOther.mpScriptNames)
{
- mpScriptNames = new OUString*[COUNT];
+ mpScriptNames.reset( new boost::optional<OUString>[COUNT] );
for (sal_Int32 nEvent=0; nEvent<COUNT; ++nEvent)
- if (rOther.mpScriptNames[nEvent])
- mpScriptNames[nEvent] = new OUString(*rOther.mpScriptNames[nEvent]);
- else
- mpScriptNames[nEvent] = nullptr;
+ mpScriptNames[nEvent] = *rOther.mpScriptNames[nEvent];
}
return *this;
}
@@ -106,7 +97,11 @@ ScSheetEvents& ScSheetEvents::operator=(const ScSheetEvents& rOther)
const OUString* ScSheetEvents::GetScript(ScSheetEventId nEvent) const
{
if (mpScriptNames)
- return mpScriptNames[static_cast<int>(nEvent)];
+ {
+ boost::optional<OUString> const & r = mpScriptNames[static_cast<int>(nEvent)];
+ if (r)
+ return &*r;
+ }
return nullptr;
}
@@ -115,15 +110,12 @@ void ScSheetEvents::SetScript(ScSheetEventId eEvent, const OUString* pNew)
int nEvent = static_cast<int>(eEvent);
if (!mpScriptNames)
{
- mpScriptNames = new OUString*[COUNT];
- for (sal_Int32 nEventIdx=0; nEventIdx<COUNT; ++nEventIdx)
- mpScriptNames[nEventIdx] = nullptr;
+ mpScriptNames.reset( new boost::optional<OUString>[COUNT] );
}
- delete mpScriptNames[nEvent];
if (pNew)
- mpScriptNames[nEvent] = new OUString(*pNew);
+ mpScriptNames[nEvent] = *pNew;
else
- mpScriptNames[nEvent] = nullptr;
+ mpScriptNames[nEvent].reset();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list