From 5a4d78d9a9b45c7fa387b66f5e310447ec813034 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 18 May 2023 11:48:26 +0200 Subject: tdf#63130 reduce large memory copies when reading from BinaryDataContainer rather than writing a bunch more code, extract the common part from comphelper::SequenceInputStream into a new base class Change-Id: I0d3561e3ca2e748b904128e3b5955e27196d7170 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151943 Tested-by: Jenkins Reviewed-by: Noel Grandin --- vcl/source/gdi/vectorgraphicdata.cxx | 6 ++---- vcl/source/graphic/BinaryDataContainer.cxx | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) (limited to 'vcl') diff --git a/vcl/source/gdi/vectorgraphicdata.cxx b/vcl/source/gdi/vectorgraphicdata.cxx index 979fd4f18ad0..7dc51073adeb 100644 --- a/vcl/source/gdi/vectorgraphicdata.cxx +++ b/vcl/source/gdi/vectorgraphicdata.cxx @@ -196,8 +196,7 @@ void VectorGraphicData::ensureSequenceAndRange() { case VectorGraphicDataType::Svg: { - css::uno::Sequence aDataSequence = maDataContainer.getCopyAsByteSequence(); - const uno::Reference xInputStream(new comphelper::SequenceInputStream(aDataSequence)); + const uno::Reference xInputStream = maDataContainer.getAsXInputStream(); const uno::Reference< graphic::XSvgParser > xSvgParser = graphic::SvgTools::create(xContext); @@ -211,8 +210,7 @@ void VectorGraphicData::ensureSequenceAndRange() { const uno::Reference< graphic::XEmfParser > xEmfParser = graphic::EmfTools::create(xContext); - css::uno::Sequence aDataSequence = maDataContainer.getCopyAsByteSequence(); - const uno::Reference xInputStream(new comphelper::SequenceInputStream(aDataSequence)); + const uno::Reference xInputStream = maDataContainer.getAsXInputStream(); if (xInputStream.is()) { diff --git a/vcl/source/graphic/BinaryDataContainer.cxx b/vcl/source/graphic/BinaryDataContainer.cxx index f395497f9449..83cacb491ac2 100644 --- a/vcl/source/graphic/BinaryDataContainer.cxx +++ b/vcl/source/graphic/BinaryDataContainer.cxx @@ -12,6 +12,7 @@ #include #include #include +#include #include struct BinaryDataContainer::Impl @@ -115,6 +116,19 @@ public: { } }; + +class ReferencedXInputStream : public comphelper::MemoryInputStream +{ + std::shared_ptr> mpData; + +public: + ReferencedXInputStream(const std::shared_ptr>& pData) + : comphelper::MemoryInputStream(reinterpret_cast(pData->data()), + pData->size()) + , mpData(pData) + { + } +}; } std::shared_ptr BinaryDataContainer::getAsStream() @@ -123,6 +137,12 @@ std::shared_ptr BinaryDataContainer::getAsStream() return std::make_shared(mpImpl->mpData); } +css::uno::Reference BinaryDataContainer::getAsXInputStream() +{ + ensureSwappedIn(); // TODO: transfer in streamed chunks + return new ReferencedXInputStream(mpImpl->mpData); +} + std::size_t BinaryDataContainer::writeToStream(SvStream& rStream) const { ensureSwappedIn(); // TODO: transfer in streamed chunks -- cgit