diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-05-18 11:48:26 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-05-18 15:15:21 +0200 |
commit | 5a4d78d9a9b45c7fa387b66f5e310447ec813034 (patch) | |
tree | 82e64c853460ae0eb54fd65adb62761e9771d5b6 /vcl | |
parent | 800f9233513a45aa8f8950cf929fd44cb9381d72 (diff) |
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 <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/gdi/vectorgraphicdata.cxx | 6 | ||||
-rw-r--r-- | vcl/source/graphic/BinaryDataContainer.cxx | 20 |
2 files changed, 22 insertions, 4 deletions
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<sal_Int8> aDataSequence = maDataContainer.getCopyAsByteSequence(); - const uno::Reference<io::XInputStream> xInputStream(new comphelper::SequenceInputStream(aDataSequence)); + const uno::Reference<io::XInputStream> 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<sal_Int8> aDataSequence = maDataContainer.getCopyAsByteSequence(); - const uno::Reference<io::XInputStream> xInputStream(new comphelper::SequenceInputStream(aDataSequence)); + const uno::Reference<io::XInputStream> 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 <o3tl/hash_combine.hxx> #include <unotools/tempfile.hxx> #include <comphelper/lok.hxx> +#include <comphelper/seqstream.hxx> #include <sal/log.hxx> struct BinaryDataContainer::Impl @@ -115,6 +116,19 @@ public: { } }; + +class ReferencedXInputStream : public comphelper::MemoryInputStream +{ + std::shared_ptr<std::vector<sal_uInt8>> mpData; + +public: + ReferencedXInputStream(const std::shared_ptr<std::vector<sal_uInt8>>& pData) + : comphelper::MemoryInputStream(reinterpret_cast<const sal_Int8*>(pData->data()), + pData->size()) + , mpData(pData) + { + } +}; } std::shared_ptr<SvStream> BinaryDataContainer::getAsStream() @@ -123,6 +137,12 @@ std::shared_ptr<SvStream> BinaryDataContainer::getAsStream() return std::make_shared<ReferencedMemoryStream>(mpImpl->mpData); } +css::uno::Reference<css::io::XInputStream> 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 |