From 2e74c1107bc8422ee7a819722f3f0a366127330f Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 17 Aug 2021 16:04:56 +0200 Subject: use visitor callback to avoid container construction (tdf#105575) Change-Id: I4dd3382ceca82f93664e66b32bcfa7c74eb58fdc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120606 Tested-by: Jenkins Reviewed-by: Noel Grandin --- .../source/processor2d/baseprocessor2d.cxx | 36 ++++++++++++---------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'drawinglayer/source') diff --git a/drawinglayer/source/processor2d/baseprocessor2d.cxx b/drawinglayer/source/processor2d/baseprocessor2d.cxx index 00d71151e887..a078fe882e9e 100644 --- a/drawinglayer/source/processor2d/baseprocessor2d.cxx +++ b/drawinglayer/source/processor2d/baseprocessor2d.cxx @@ -41,28 +41,32 @@ namespace drawinglayer::processor2d void BaseProcessor2D::process(const primitive2d::BasePrimitive2D& rCandidate) { - primitive2d::Primitive2DContainer aContainer; - rCandidate.get2DDecomposition(aContainer, getViewInformation2D()); - process(aContainer); + // use the visitor API to avoid the cost of constructing Primitive2DContainers + rCandidate.get2DDecomposition(*this, getViewInformation2D()); } - void BaseProcessor2D::process(const primitive2d::Primitive2DContainer& rSource) + // Primitive2DDecompositionVisitor + void BaseProcessor2D::append(const primitive2d::Primitive2DReference& rCandidate) { - if(rSource.empty()) - return; - - const sal_Int32 nCount(rSource.size()); + const primitive2d::BasePrimitive2D* pBasePrimitive = static_cast< const primitive2d::BasePrimitive2D* >(rCandidate.get()); + processBasePrimitive2D(*pBasePrimitive); + } + void BaseProcessor2D::append(const primitive2d::Primitive2DContainer& rContainer) + { + process(rContainer); + } + void BaseProcessor2D::append(primitive2d::Primitive2DContainer&& rCandidate) + { + process(rCandidate); + } - for(sal_Int32 a(0); a < nCount; a++) + void BaseProcessor2D::process(const primitive2d::Primitive2DContainer& rSource) + { + for (const primitive2d::Primitive2DReference& rCandidate : rSource) { - // get reference - const primitive2d::Primitive2DReference xReference(rSource[a]); - - if(xReference.is()) - { - const primitive2d::BasePrimitive2D* pBasePrimitive = static_cast< const primitive2d::BasePrimitive2D* >(xReference.get()); + const primitive2d::BasePrimitive2D* pBasePrimitive = static_cast< const primitive2d::BasePrimitive2D* >(rCandidate.get()); + if (pBasePrimitive) processBasePrimitive2D(*pBasePrimitive); - } } } -- cgit