summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-04-21 07:51:25 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-05-01 08:26:24 +0200
commited8152b1ed9baf859966fd21d6641dfba9c4467c (patch)
treeb4f7b372433c5da3b8df41d026ff95fecece9ce6 /sfx2
parent6cb9b06432434fb3257118743780828b3b57326a (diff)
improve loplugin:makeshared
to find places where we are converting stuff to unique_ptr instead of using std::make_shared. As a bonus, this tends to find places where we are using shared_ptr where we can instead be using unique_ptr avoiding the locking overhead. Change-Id: I1b57bbc4a6c766b48bba8e25a55161800e149f62 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93207 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/qa/cppunit/test_misc.cxx2
-rw-r--r--sfx2/source/doc/objstor.cxx41
-rw-r--r--sfx2/source/doc/oleprops.cxx13
3 files changed, 26 insertions, 30 deletions
diff --git a/sfx2/qa/cppunit/test_misc.cxx b/sfx2/qa/cppunit/test_misc.cxx
index 587cec0047fe..f616b3e8cea2 100644
--- a/sfx2/qa/cppunit/test_misc.cxx
+++ b/sfx2/qa/cppunit/test_misc.cxx
@@ -87,7 +87,7 @@ CPPUNIT_TEST_FIXTURE(MiscTest, testODFCustomMetadata)
uno::Reference<packages::zip::XZipFileAccess2> const xZip(
packages::zip::ZipFileAccess::createWithURL(m_xContext, aTempFile.GetURL()));
uno::Reference<io::XInputStream> const xInputStream(xZip->getByName("meta.xml"), uno::UNO_QUERY);
- std::shared_ptr<SvStream> const pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true));
+ std::unique_ptr<SvStream> const pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true));
xmlDocPtr pXmlDoc = parseXmlStream(pStream.get());
assertXPathContent(pXmlDoc, "/office:document-meta/office:meta/bork", "bork");
assertXPath(pXmlDoc, "/office:document-meta/office:meta/foo:bar", 1);
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index 67e642171f06..ff64c1491382 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -2481,7 +2481,7 @@ bool SfxObjectShell::DoSave_Impl( const SfxItemSet* pArgs )
// copy the original itemset, but remove the "version" item, because pMediumTmp
// is a new medium "from scratch", so no version should be stored into it
- std::unique_ptr<SfxItemSet> pSet(new SfxAllItemSet(*pRetrMedium->GetItemSet()));
+ std::shared_ptr<SfxItemSet> pSet = std::make_shared<SfxAllItemSet>(*pRetrMedium->GetItemSet());
pSet->ClearItem( SID_VERSION );
pSet->ClearItem( SID_DOC_BASEURL );
@@ -2745,52 +2745,51 @@ bool SfxObjectShell::PreDoSaveAs_Impl(const OUString& rFileName, const OUString&
const uno::Sequence<beans::PropertyValue>& rArgs)
{
// copy all items stored in the itemset of the current medium
- std::unique_ptr<SfxAllItemSet> pMergedParams(new SfxAllItemSet( *pMedium->GetItemSet() ));
+ std::shared_ptr<SfxAllItemSet> xMergedParams = std::make_shared<SfxAllItemSet>( *pMedium->GetItemSet() );
// in "SaveAs" title and password will be cleared ( maybe the new itemset contains new values, otherwise they will be empty )
// #i119366# - As the SID_ENCRYPTIONDATA and SID_PASSWORD are using for setting password together, we need to clear them both.
// Also, ( maybe the new itemset contains new values, otherwise they will be empty )
- if (pMergedParams->HasItem( SID_PASSWORD ))
+ if (xMergedParams->HasItem( SID_PASSWORD ))
{
- pMergedParams->ClearItem( SID_PASSWORD );
- pMergedParams->ClearItem( SID_ENCRYPTIONDATA );
+ xMergedParams->ClearItem( SID_PASSWORD );
+ xMergedParams->ClearItem( SID_ENCRYPTIONDATA );
}
- pMergedParams->ClearItem( SID_DOCINFO_TITLE );
+ xMergedParams->ClearItem( SID_DOCINFO_TITLE );
- pMergedParams->ClearItem( SID_INPUTSTREAM );
- pMergedParams->ClearItem( SID_STREAM );
- pMergedParams->ClearItem( SID_CONTENT );
- pMergedParams->ClearItem( SID_DOC_READONLY );
- pMergedParams->ClearItem( SID_DOC_BASEURL );
+ xMergedParams->ClearItem( SID_INPUTSTREAM );
+ xMergedParams->ClearItem( SID_STREAM );
+ xMergedParams->ClearItem( SID_CONTENT );
+ xMergedParams->ClearItem( SID_DOC_READONLY );
+ xMergedParams->ClearItem( SID_DOC_BASEURL );
- pMergedParams->ClearItem( SID_REPAIRPACKAGE );
+ xMergedParams->ClearItem( SID_REPAIRPACKAGE );
// "SaveAs" will never store any version information - it's a complete new file !
- pMergedParams->ClearItem( SID_VERSION );
+ xMergedParams->ClearItem( SID_VERSION );
// merge the new parameters into the copy
// all values present in both itemsets will be overwritten by the new parameters
- pMergedParams->Put(rItemSet);
+ xMergedParams->Put(rItemSet);
- SAL_WARN_IF( pMergedParams->GetItemState( SID_DOC_SALVAGE) >= SfxItemState::SET,
+ SAL_WARN_IF( xMergedParams->GetItemState( SID_DOC_SALVAGE) >= SfxItemState::SET,
"sfx.doc","Salvage item present in Itemset, check the parameters!");
// should be unnecessary - too hot to handle!
- pMergedParams->ClearItem( SID_DOC_SALVAGE );
+ xMergedParams->ClearItem( SID_DOC_SALVAGE );
// create a medium for the target URL
- auto pMergedParamsTmp = pMergedParams.get();
- SfxMedium *pNewFile = new SfxMedium( rFileName, StreamMode::READWRITE | StreamMode::SHARE_DENYWRITE | StreamMode::TRUNC, nullptr, std::move(pMergedParams) );
+ SfxMedium *pNewFile = new SfxMedium( rFileName, StreamMode::READWRITE | StreamMode::SHARE_DENYWRITE | StreamMode::TRUNC, nullptr, xMergedParams );
pNewFile->SetArgs(rArgs);
- const SfxBoolItem* pNoFileSync = pMergedParamsTmp->GetItem<SfxBoolItem>(SID_NO_FILE_SYNC, false);
+ const SfxBoolItem* pNoFileSync = xMergedParams->GetItem<SfxBoolItem>(SID_NO_FILE_SYNC, false);
if (pNoFileSync && pNoFileSync->GetValue())
pNewFile->DisableFileSync(true);
bool bUseThumbnailSave = IsUseThumbnailSave();
comphelper::ScopeGuard aThumbnailGuard(
[this, bUseThumbnailSave] { this->SetUseThumbnailSave(bUseThumbnailSave); });
- const SfxBoolItem* pNoThumbnail = pMergedParamsTmp->GetItem<SfxBoolItem>(SID_NO_THUMBNAIL, false);
+ const SfxBoolItem* pNoThumbnail = xMergedParams->GetItem<SfxBoolItem>(SID_NO_THUMBNAIL, false);
if (pNoThumbnail)
// Thumbnail generation should be avoided just for this save.
SetUseThumbnailSave(!pNoThumbnail->GetValue());
@@ -2818,7 +2817,7 @@ bool SfxObjectShell::PreDoSaveAs_Impl(const OUString& rFileName, const OUString&
}
// check if a "SaveTo" is wanted, no "SaveAs"
- const SfxBoolItem* pSaveToItem = pMergedParamsTmp->GetItem<SfxBoolItem>(SID_SAVETO, false);
+ const SfxBoolItem* pSaveToItem = xMergedParams->GetItem<SfxBoolItem>(SID_SAVETO, false);
bool bCopyTo = GetCreateMode() == SfxObjectCreateMode::EMBEDDED || (pSaveToItem && pSaveToItem->GetValue());
// distinguish between "Save" and "SaveAs"
diff --git a/sfx2/source/doc/oleprops.cxx b/sfx2/source/doc/oleprops.cxx
index 14b6e4863ad6..c3baa5d21151 100644
--- a/sfx2/source/doc/oleprops.cxx
+++ b/sfx2/source/doc/oleprops.cxx
@@ -845,20 +845,17 @@ void SfxOleSection::SetDateValue( sal_Int32 nPropId, const util::Date& rValue )
void SfxOleSection::SetThumbnailValue( sal_Int32 nPropId,
const uno::Sequence<sal_Int8> & i_rData)
{
- SfxOleThumbnailProperty* pThumbnail = new SfxOleThumbnailProperty( nPropId, i_rData );
- SfxOlePropertyRef xProp( pThumbnail ); // take ownership
+ auto pThumbnail = std::make_shared<SfxOleThumbnailProperty>( nPropId, i_rData );
if( pThumbnail->IsValid() )
- SetProperty( xProp );
+ SetProperty( pThumbnail );
}
void SfxOleSection::SetBlobValue( sal_Int32 nPropId,
const uno::Sequence<sal_Int8> & i_rData)
{
- SfxOleBlobProperty* pBlob( new SfxOleBlobProperty( nPropId, i_rData ) );
- SfxOlePropertyRef xProp( pBlob );
- if( pBlob->IsValid() ) {
- SetProperty( xProp );
- }
+ auto pBlob = std::make_shared<SfxOleBlobProperty>( nPropId, i_rData );
+ if( pBlob->IsValid() )
+ SetProperty( pBlob );
}
Any SfxOleSection::GetAnyValue( sal_Int32 nPropId ) const