diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-21 07:51:25 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-05-01 08:26:24 +0200 |
commit | ed8152b1ed9baf859966fd21d6641dfba9c4467c (patch) | |
tree | b4f7b372433c5da3b8df41d026ff95fecece9ce6 /sd | |
parent | 6cb9b06432434fb3257118743780828b3b57326a (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 'sd')
-rw-r--r-- | sd/qa/unit/export-tests-ooxml1.cxx | 2 | ||||
-rw-r--r-- | sd/qa/unit/export-tests-ooxml2.cxx | 4 | ||||
-rw-r--r-- | sd/qa/unit/sdmodeltestbase.hxx | 18 | ||||
-rw-r--r-- | sd/source/ui/dlg/sddlgfact.cxx | 14 | ||||
-rw-r--r-- | sd/source/ui/dlg/sddlgfact.hxx | 8 | ||||
-rw-r--r-- | sd/source/ui/slidesorter/cache/SlsBitmapCompressor.cxx | 8 |
6 files changed, 26 insertions, 28 deletions
diff --git a/sd/qa/unit/export-tests-ooxml1.cxx b/sd/qa/unit/export-tests-ooxml1.cxx index 769bf6e52456..bb5d2add3f52 100644 --- a/sd/qa/unit/export-tests-ooxml1.cxx +++ b/sd/qa/unit/export-tests-ooxml1.cxx @@ -882,7 +882,7 @@ void SdOOXMLExportTest1::testCustomXml() assertXPath(pRelsDoc, "/rels:Relationships/rels:Relationship", 1); assertXPath(pRelsDoc, "/rels:Relationships/rels:Relationship[@Id='rId1']", "Target", "itemProps1.xml"); - std::shared_ptr<SvStream> pStream = parseExportStream(tempFile, "ddp/ddpfile.xen"); + std::unique_ptr<SvStream> pStream = parseExportStream(tempFile, "ddp/ddpfile.xen"); CPPUNIT_ASSERT(pStream); } diff --git a/sd/qa/unit/export-tests-ooxml2.cxx b/sd/qa/unit/export-tests-ooxml2.cxx index 6f77a2ecd849..7b0c9788e71b 100644 --- a/sd/qa/unit/export-tests-ooxml2.cxx +++ b/sd/qa/unit/export-tests-ooxml2.cxx @@ -2318,10 +2318,10 @@ void SdOOXMLExportTest2::testTdf44223() = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/tdf44223.pptx"), PPTX); xDocShRef = saveAndReload(xDocShRef.get(), PPTX, &tempFile); - std::shared_ptr<SvStream> const pStream1(parseExportStream(tempFile, "ppt/media/audio1.wav")); + std::unique_ptr<SvStream> const pStream1(parseExportStream(tempFile, "ppt/media/audio1.wav")); CPPUNIT_ASSERT_EQUAL(sal_uInt64(11140), pStream1->remainingSize()); - std::shared_ptr<SvStream> const pStream2(parseExportStream(tempFile, "ppt/media/audio2.wav")); + std::unique_ptr<SvStream> const pStream2(parseExportStream(tempFile, "ppt/media/audio2.wav")); CPPUNIT_ASSERT_EQUAL(sal_uInt64(28074), pStream2->remainingSize()); xmlDocPtr pXmlContentType = parseExport(tempFile, "[Content_Types].xml"); diff --git a/sd/qa/unit/sdmodeltestbase.hxx b/sd/qa/unit/sdmodeltestbase.hxx index a490dcee60ee..b97313ffec6d 100644 --- a/sd/qa/unit/sdmodeltestbase.hxx +++ b/sd/qa/unit/sdmodeltestbase.hxx @@ -133,7 +133,7 @@ public: protected: /// Load the document. - sd::DrawDocShellRef loadURL( const OUString &rURL, sal_Int32 nFormat, std::unique_ptr<SfxAllItemSet> pParams = nullptr ) + sd::DrawDocShellRef loadURL( const OUString &rURL, sal_Int32 nFormat, std::shared_ptr<SfxAllItemSet> pParams = nullptr ) { FileFormat *pFmt = getFormat(nFormat); CPPUNIT_ASSERT_MESSAGE( "missing filter info", pFmt->pName != nullptr ); @@ -142,7 +142,7 @@ protected: SotClipboardFormatId nOptions = SotClipboardFormatId::NONE; if (pFmt->nFormatType != SfxFilterFlags::NONE) nOptions = SotClipboardFormatId::STARDRAW_8; - SfxFilter* pFilter = new SfxFilter( + auto pFilter = std::make_shared<SfxFilter>( OUString::createFromAscii( pFmt->pFilterName ), OUString(), pFmt->nFormatType, nOptions, OUString::createFromAscii( pFmt->pTypeName ), @@ -150,10 +150,9 @@ protected: OUString::createFromAscii( pFmt->pUserData ), "private:factory/sdraw*" ); pFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT); - std::shared_ptr<const SfxFilter> pFilt(pFilter); ::sd::DrawDocShellRef xDocShRef = new ::sd::GraphicDocShell(SfxObjectCreateMode::EMBEDDED); - SfxMedium* pSrcMed = new SfxMedium(rURL, StreamMode::STD_READ, pFilt, std::move(pParams)); + SfxMedium* pSrcMed = new SfxMedium(rURL, StreamMode::STD_READ, pFilter, std::move(pParams)); if ( !xDocShRef->DoLoad(pSrcMed) || !xDocShRef.is() ) { if (xDocShRef.is()) @@ -168,7 +167,7 @@ protected: SotClipboardFormatId nOptions = SotClipboardFormatId::NONE; if (pFmt->nFormatType != SfxFilterFlags::NONE) nOptions = SotClipboardFormatId::STARIMPRESS_8; - SfxFilter* pFilter = new SfxFilter( + auto pFilter = std::make_shared<SfxFilter>( OUString::createFromAscii( pFmt->pFilterName ), OUString(), pFmt->nFormatType, nOptions, OUString::createFromAscii( pFmt->pTypeName ), @@ -176,10 +175,9 @@ protected: OUString::createFromAscii( pFmt->pUserData ), "private:factory/simpress*" ); pFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT); - std::shared_ptr<const SfxFilter> pFilt(pFilter); ::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell(SfxObjectCreateMode::EMBEDDED, false, DocumentType::Impress); - SfxMedium* pSrcMed = new SfxMedium(rURL, StreamMode::STD_READ, pFilt, std::move(pParams)); + SfxMedium* pSrcMed = new SfxMedium(rURL, StreamMode::STD_READ, pFilter, std::move(pParams)); if ( !xDocShRef->DoLoad(pSrcMed) || !xDocShRef.is() ) { if (xDocShRef.is()) @@ -445,20 +443,20 @@ class SdModelTestBaseXML { public: - std::shared_ptr<SvStream> parseExportStream(utl::TempFile const & rTempFile, const OUString& rStreamName) + std::unique_ptr<SvStream> parseExportStream(utl::TempFile const & rTempFile, const OUString& rStreamName) { // Read the stream we're interested in. OUString const url(rTempFile.GetURL()); uno::Reference<packages::zip::XZipFileAccess2> const xZipNames(packages::zip::ZipFileAccess::createWithURL( comphelper::getComponentContext(m_xSFactory), url)); uno::Reference<io::XInputStream> const xInputStream(xZipNames->getByName(rStreamName), uno::UNO_QUERY); - std::shared_ptr<SvStream> const pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); + std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); return pStream; } xmlDocPtr parseExport(utl::TempFile const & rTempFile, OUString const& rStreamName) { - std::shared_ptr<SvStream> const pStream(parseExportStream(rTempFile, rStreamName)); + std::unique_ptr<SvStream> const pStream(parseExportStream(rTempFile, rStreamName)); xmlDocPtr const pXmlDoc = parseXmlStream(pStream.get()); OUString const url(rTempFile.GetURL()); pXmlDoc->name = reinterpret_cast<char *>(xmlStrdup( diff --git a/sd/source/ui/dlg/sddlgfact.cxx b/sd/source/ui/dlg/sddlgfact.cxx index 117064161ec5..8db686217c86 100644 --- a/sd/source/ui/dlg/sddlgfact.cxx +++ b/sd/source/ui/dlg/sddlgfact.cxx @@ -638,12 +638,12 @@ VclPtr<AbstractSdCustomShowDlg> SdAbstractDialogFactory_Impl::CreateSdCustomShow VclPtr<SfxAbstractTabDialog> SdAbstractDialogFactory_Impl::CreateSdTabCharDialog(weld::Window* pParent, const SfxItemSet* pAttr, SfxObjectShell* pDocShell) { - return VclPtr<SdAbstractTabController_Impl>::Create(std::make_unique<SdCharDlg>(pParent, pAttr, pDocShell)); + return VclPtr<SdAbstractTabController_Impl>::Create(std::make_shared<SdCharDlg>(pParent, pAttr, pDocShell)); } VclPtr<SfxAbstractTabDialog> SdAbstractDialogFactory_Impl::CreateSdTabPageDialog(weld::Window* pParent, const SfxItemSet* pAttr, SfxObjectShell* pDocShell, bool bAreaPage, bool bIsImpressDoc ) { - return VclPtr<SdAbstractTabController_Impl>::Create(std::make_unique<SdPageDlg>(pDocShell, pParent, pAttr, bAreaPage, bIsImpressDoc)); + return VclPtr<SdAbstractTabController_Impl>::Create(std::make_shared<SdPageDlg>(pDocShell, pParent, pAttr, bAreaPage, bIsImpressDoc)); } VclPtr<AbstractSdModifyFieldDlg> SdAbstractDialogFactory_Impl::CreateSdModifyFieldDlg(weld::Window* pParent, const SvxFieldData* pInField, const SfxItemSet& rSet) @@ -673,12 +673,12 @@ VclPtr<AbstractMorphDlg> SdAbstractDialogFactory_Impl::CreateMorphDlg(weld::Wind VclPtr<SfxAbstractTabDialog> SdAbstractDialogFactory_Impl::CreateSdOutlineBulletTabDlg(weld::Window* pParent, const SfxItemSet* pAttr, ::sd::View* pView) { - return VclPtr<AbstractBulletDialog_Impl>::Create(std::make_unique<::sd::OutlineBulletDlg>(pParent, pAttr, pView)); + return VclPtr<AbstractBulletDialog_Impl>::Create(std::make_shared<::sd::OutlineBulletDlg>(pParent, pAttr, pView)); } VclPtr<SfxAbstractTabDialog> SdAbstractDialogFactory_Impl::CreateSdParagraphTabDlg(weld::Window* pParent, const SfxItemSet* pAttr ) { - return VclPtr<SdAbstractTabController_Impl>::Create(std::make_unique<SdParagraphDlg>(pParent, pAttr)); + return VclPtr<SdAbstractTabController_Impl>::Create(std::make_shared<SdParagraphDlg>(pParent, pAttr)); } VclPtr<AbstractSdStartPresDlg> SdAbstractDialogFactory_Impl::CreateSdStartPresentationDlg(weld::Window* pParent, @@ -694,7 +694,7 @@ VclPtr<VclAbstractDialog> SdAbstractDialogFactory_Impl::CreateRemoteDialog(weld: VclPtr<SfxAbstractTabDialog> SdAbstractDialogFactory_Impl::CreateSdPresLayoutTemplateDlg(SfxObjectShell* pDocSh, weld::Window* pParent, bool bBackgroundDlg, SfxStyleSheetBase& rStyleBase, PresentationObjects ePO, SfxStyleSheetBasePool* pSSPool) { - return VclPtr<SdPresLayoutTemplateDlg_Impl>::Create(std::make_unique<SdPresLayoutTemplateDlg>(pDocSh, pParent, bBackgroundDlg, rStyleBase, ePO, pSSPool)); + return VclPtr<SdPresLayoutTemplateDlg_Impl>::Create(std::make_shared<SdPresLayoutTemplateDlg>(pDocSh, pParent, bBackgroundDlg, rStyleBase, ePO, pSSPool)); } VclPtr<AbstractSdPresLayoutDlg> SdAbstractDialogFactory_Impl::CreateSdPresLayoutDlg(weld::Window* pParent, ::sd::DrawDocShell* pDocShell, const SfxItemSet& rInAttrs) @@ -704,7 +704,7 @@ VclPtr<AbstractSdPresLayoutDlg> SdAbstractDialogFactory_Impl::CreateSdPresLayout VclPtr<SfxAbstractTabDialog> SdAbstractDialogFactory_Impl::CreateSdTabTemplateDlg(weld::Window* pParent, const SfxObjectShell* pDocShell, SfxStyleSheetBase& rStyleBase, SdrModel* pModel, SdrView* pView) { - return VclPtr<SdAbstractTabController_Impl>::Create(std::make_unique<SdTabTemplateDlg>(pParent, pDocShell, rStyleBase, pModel, pView)); + return VclPtr<SdAbstractTabController_Impl>::Create(std::make_shared<SdTabTemplateDlg>(pParent, pDocShell, rStyleBase, pModel, pView)); } VclPtr<SfxAbstractDialog> SdAbstractDialogFactory_Impl::CreatSdActionDialog(weld::Window* pParent, const SfxItemSet* pAttr, ::sd::View* pView ) @@ -751,7 +751,7 @@ VclPtr<VclAbstractDialog> SdAbstractDialogFactory_Impl::CreateMasterLayoutDialog VclPtr<AbstractHeaderFooterDialog> SdAbstractDialogFactory_Impl::CreateHeaderFooterDialog(sd::ViewShell* pViewShell, weld::Window* pParent, SdDrawDocument* pDoc, SdPage* pCurrentPage) { - return VclPtr<AbstractHeaderFooterDialog_Impl>::Create(std::make_unique<::sd::HeaderFooterDialog>(pViewShell, pParent, pDoc, pCurrentPage)); + return VclPtr<AbstractHeaderFooterDialog_Impl>::Create(std::make_shared<::sd::HeaderFooterDialog>(pViewShell, pParent, pDoc, pCurrentPage)); } VclPtr<VclAbstractDialog> SdAbstractDialogFactory_Impl::CreateSdPhotoAlbumDialog(weld::Window* pParent, SdDrawDocument* pDoc) diff --git a/sd/source/ui/dlg/sddlgfact.hxx b/sd/source/ui/dlg/sddlgfact.hxx index 257a1614dc6d..75071a54f07a 100644 --- a/sd/source/ui/dlg/sddlgfact.hxx +++ b/sd/source/ui/dlg/sddlgfact.hxx @@ -146,7 +146,7 @@ class SdAbstractTabController_Impl : public SfxAbstractTabDialog { std::shared_ptr<SfxTabDialogController> m_xDlg; public: - explicit SdAbstractTabController_Impl(std::unique_ptr<SfxTabDialogController> p) + explicit SdAbstractTabController_Impl(std::shared_ptr<SfxTabDialogController> p) : m_xDlg(std::move(p)) { } @@ -167,7 +167,7 @@ class AbstractBulletDialog_Impl : public SfxAbstractTabDialog { std::shared_ptr<SfxTabDialogController> m_xDlg; public: - explicit AbstractBulletDialog_Impl(std::unique_ptr<SfxTabDialogController> p) + explicit AbstractBulletDialog_Impl(std::shared_ptr<SfxTabDialogController> p) : m_xDlg(std::move(p)) { } @@ -188,7 +188,7 @@ class SdPresLayoutTemplateDlg_Impl : public SfxAbstractTabDialog { std::shared_ptr<SdPresLayoutTemplateDlg> m_xDlg; public: - explicit SdPresLayoutTemplateDlg_Impl(std::unique_ptr<SdPresLayoutTemplateDlg> p) + explicit SdPresLayoutTemplateDlg_Impl(std::shared_ptr<SdPresLayoutTemplateDlg> p) : m_xDlg(std::move(p)) { } @@ -388,7 +388,7 @@ class AbstractHeaderFooterDialog_Impl :public AbstractHeaderFooterDialog private: std::shared_ptr<::sd::HeaderFooterDialog> m_xDlg; public: - AbstractHeaderFooterDialog_Impl(std::unique_ptr<::sd::HeaderFooterDialog> pDlg) + AbstractHeaderFooterDialog_Impl(std::shared_ptr<::sd::HeaderFooterDialog> pDlg) : m_xDlg(std::move(pDlg)) { } diff --git a/sd/source/ui/slidesorter/cache/SlsBitmapCompressor.cxx b/sd/source/ui/slidesorter/cache/SlsBitmapCompressor.cxx index da5a440dd882..04b99dbf6c15 100644 --- a/sd/source/ui/slidesorter/cache/SlsBitmapCompressor.cxx +++ b/sd/source/ui/slidesorter/cache/SlsBitmapCompressor.cxx @@ -102,7 +102,7 @@ sal_Int32 ResolutionReduction::ResolutionReducedReplacement::GetMemorySize() con std::shared_ptr<BitmapReplacement> ResolutionReduction::Compress ( const BitmapEx& rBitmap) const { - ResolutionReducedReplacement* pResult = new ResolutionReducedReplacement; + auto pResult = std::make_shared<ResolutionReducedReplacement>(); pResult->maPreview = rBitmap; Size aSize (rBitmap.GetSizePixel()); pResult->maOriginalSize = aSize; @@ -112,7 +112,7 @@ std::shared_ptr<BitmapReplacement> ResolutionReduction::Compress ( pResult->maPreview.Scale(Size(mnWidth,nHeight)); } - return std::shared_ptr<BitmapReplacement>(pResult); + return pResult; } BitmapEx ResolutionReduction::Decompress (const BitmapReplacement& rBitmapData) const @@ -164,12 +164,12 @@ std::shared_ptr<BitmapReplacement> PngCompression::Compress (const BitmapEx& rBi SvMemoryStream aStream (32768, 32768); aWriter.Write(aStream); - PngReplacement* pResult = new PngReplacement(); + auto pResult = std::make_shared<PngReplacement>(); pResult->mnDataSize = aStream.Tell(); pResult->mpData = new char[pResult->mnDataSize]; memcpy(pResult->mpData, aStream.GetData(), pResult->mnDataSize); - return std::shared_ptr<BitmapReplacement>(pResult); + return pResult; } BitmapEx PngCompression::Decompress ( |