[Libreoffice-commits] core.git: drawinglayer/source include/drawinglayer
Noel Grandin (via logerrit)
logerrit at kemper.freedesktop.org
Wed Aug 18 19:17:57 UTC 2021
drawinglayer/source/processor2d/baseprocessor2d.cxx | 36 ++++++++++---------
include/drawinglayer/processor2d/baseprocessor2d.hxx | 7 +++
2 files changed, 26 insertions(+), 17 deletions(-)
New commits:
commit 2e74c1107bc8422ee7a819722f3f0a366127330f
Author: Noel Grandin <noel at peralex.com>
AuthorDate: Tue Aug 17 16:04:56 2021 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Aug 18 21:17:19 2021 +0200
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 <noel.grandin at collabora.co.uk>
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);
- }
}
}
diff --git a/include/drawinglayer/processor2d/baseprocessor2d.hxx b/include/drawinglayer/processor2d/baseprocessor2d.hxx
index 1f0bd46efb62..4f1515109a77 100644
--- a/include/drawinglayer/processor2d/baseprocessor2d.hxx
+++ b/include/drawinglayer/processor2d/baseprocessor2d.hxx
@@ -22,6 +22,7 @@
#include <drawinglayer/drawinglayerdllapi.h>
+#include <drawinglayer/primitive2d/Primitive2DVisitor.hxx>
#include <drawinglayer/primitive2d/baseprimitive2d.hxx>
#include <drawinglayer/geometry/viewinformation2d.hxx>
@@ -150,7 +151,7 @@ namespace drawinglayer::processor2d
be helpful to add many for the purpose not interesting higher level primitives
to not force their decomposition to be created and/or parsed.
*/
- class DRAWINGLAYER_DLLPUBLIC BaseProcessor2D
+ class DRAWINGLAYER_DLLPUBLIC BaseProcessor2D : public drawinglayer::primitive2d::Primitive2DDecompositionVisitor
{
private:
/// The ViewInformation2D itself. It's private to isolate accesses to it
@@ -174,6 +175,10 @@ namespace drawinglayer::processor2d
void process(const primitive2d::BasePrimitive2D& rCandidate);
+ // Primitive2DDecompositionVisitor
+ virtual void append(const primitive2d::Primitive2DReference&) override final;
+ virtual void append(const primitive2d::Primitive2DContainer&) override final;
+ virtual void append(primitive2d::Primitive2DContainer&&) override final;
public:
/// constructor/destructor
More information about the Libreoffice-commits
mailing list