include/vcl/graphicfilter.hxx | 2 +- vcl/source/filter/graphicfilter.cxx | 19 +++++++------------ vcl/source/graphic/UnoGraphicProvider.cxx | 8 ++------ 3 files changed, 10 insertions(+), 19 deletions(-)
New commits: commit 4535ccfc5eabfbe3b6e49856d861349b55d201e6 Author: Mike Kaganski <[email protected]> AuthorDate: Thu Oct 2 13:01:47 2025 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Sat Oct 4 13:42:35 2025 +0200 Put Graphic into vector by value, instead of using shared_ptr This was just unneeded overhead. Change-Id: Ic23d25195f6302e62fd06eb2734f97dd1a5c1f9b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191850 Reviewed-by: Mike Kaganski <[email protected]> Tested-by: Jenkins diff --git a/include/vcl/graphicfilter.hxx b/include/vcl/graphicfilter.hxx index 12f5d3bfc967..c502cb8541d2 100644 --- a/include/vcl/graphicfilter.hxx +++ b/include/vcl/graphicfilter.hxx @@ -283,7 +283,7 @@ public: /// Imports multiple graphics. /// /// The resulting graphic is added to result on success, empty graphic is added on failure. - SAL_DLLPRIVATE std::vector<std::shared_ptr<Graphic>> ImportGraphics(std::vector< std::unique_ptr<SvStream> > vStreams); + SAL_DLLPRIVATE std::vector<Graphic> ImportGraphics(std::vector< std::unique_ptr<SvStream> > vStreams); /** Tries to ensure all Graphic objects are available (Graphic::isAvailable()). Only an optimization, may diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx index 4dcb30256b40..b3d30f0c4a10 100644 --- a/vcl/source/filter/graphicfilter.cxx +++ b/vcl/source/filter/graphicfilter.cxx @@ -534,7 +534,7 @@ void GraphicImportTask::doImport(GraphicImportContext& rContext) } } -std::vector<std::shared_ptr<Graphic>> GraphicFilter::ImportGraphics(std::vector< std::unique_ptr<SvStream> > vStreams) +std::vector<Graphic> GraphicFilter::ImportGraphics(std::vector<std::unique_ptr<SvStream>> vStreams) { static bool bThreads = !getenv("VCL_NO_THREAD_IMPORT"); std::vector<GraphicImportContext> aContexts; @@ -608,18 +608,16 @@ std::vector<std::shared_ptr<Graphic>> GraphicFilter::ImportGraphics(std::vector< rSharedPool.waitUntilDone(pTag); // Process data after import. - std::vector<std::shared_ptr<Graphic>> aGraphics; + std::vector<Graphic> aGraphics; aGraphics.reserve(aContexts.size()); for (auto& rContext : aContexts) { rContext.m_pAccess.reset(); - std::shared_ptr<Graphic> pGraphic; - if (rContext.m_nStatus == ERRCODE_NONE && rContext.m_pImportOutput && rContext.m_pImportOutput->moBitmap) - pGraphic = std::make_shared<Graphic>(*rContext.m_pImportOutput->moBitmap); + aGraphics.emplace_back(*rContext.m_pImportOutput->moBitmap); else - pGraphic = std::make_shared<Graphic>(); + aGraphics.emplace_back(); if (rContext.m_nStatus == ERRCODE_NONE && rContext.m_eLinkType != GfxLinkType::NONE) { @@ -642,10 +640,8 @@ std::vector<std::shared_ptr<Graphic>> GraphicFilter::ImportGraphics(std::vector< } if (rContext.m_nStatus == ERRCODE_NONE) - pGraphic->SetGfxLink(std::make_shared<GfxLink>(aGraphicContent, rContext.m_eLinkType)); + aGraphics.back().SetGfxLink(std::make_shared<GfxLink>(aGraphicContent, rContext.m_eLinkType)); } - - aGraphics.push_back(std::move(pGraphic)); } return aGraphics; } @@ -678,12 +674,11 @@ void GraphicFilter::MakeGraphicsAvailableThreaded(std::vector<Graphic*>& graphic { streams.push_back(graphic->GetSharedGfxLink()->getDataContainer().getAsStream()); } - std::vector<std::shared_ptr<Graphic>> loadedGraphics = ImportGraphics(std::move(streams)); + std::vector<Graphic> loadedGraphics = ImportGraphics(std::move(streams)); assert(loadedGraphics.size() == toLoad.size()); for( size_t i = 0; i < toLoad.size(); ++i ) { - assert(loadedGraphics[ i ] != nullptr); - toLoad[ i ]->ImplGetImpGraphic()->updateFromLoadedGraphic(loadedGraphics[ i ]->ImplGetImpGraphic()); + toLoad[ i ]->ImplGetImpGraphic()->updateFromLoadedGraphic(loadedGraphics[ i ].ImplGetImpGraphic()); } } diff --git a/vcl/source/graphic/UnoGraphicProvider.cxx b/vcl/source/graphic/UnoGraphicProvider.cxx index a53e8b54838a..150f0d6fc795 100644 --- a/vcl/source/graphic/UnoGraphicProvider.cxx +++ b/vcl/source/graphic/UnoGraphicProvider.cxx @@ -438,16 +438,12 @@ uno::Sequence< uno::Reference<graphic::XGraphic> > SAL_CALL GraphicProvider::que // Import: streams to graphics. GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter(); - std::vector<std::shared_ptr<Graphic>> aGraphics = rFilter.ImportGraphics(std::move(aStreams)); + std::vector<Graphic> aGraphics = rFilter.ImportGraphics(std::move(aStreams)); // Returning: graphics to UNO objects. uno::Sequence<uno::Reference<graphic::XGraphic>> aRet(aGraphics.size()); std::transform(aGraphics.begin(), aGraphics.end(), aRet.getArray(), - [](const auto& pGraphic) - { - assert(pGraphic); - return pGraphic->GetXGraphic(); - }); + [](const auto& rGraphic) { return rGraphic.GetXGraphic(); }); return aRet; }
