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-06-01 07:58:21 +0200 |
commit | a4d24f9a2af7cf5d6cceeedfaaa744d4da62c7a8 (patch) | |
tree | c49f7fbfff4822e4d1e3d787464dfd6b90f023c5 /vcl | |
parent | 19c786bb99d61f7309019a7cccf7e3e2cb179ea9 (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>
(cherry picked from commit 5a4d78d9a9b45c7fa387b66f5e310447ec813034)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151916
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
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 1abc1ce097d2..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.getAsSequence(); - 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.getAsSequence(); - 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 cfbd4560a8d5..43538f9b12fd 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 @@ -114,12 +115,31 @@ 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() { ensureSwappedIn(); // TODO: transfer in streamed chunks 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 |