include/svx/annotation/ObjectAnnotationData.hxx |    5 +----
 include/svx/svdobj.hxx                          |    4 ++--
 sd/source/ui/annotations/annotationmanager.cxx  |    2 +-
 svx/source/annotation/AnnotationObject.cxx      |    2 +-
 svx/source/svdraw/svdobj.cxx                    |   12 +++---------
 svx/source/svdraw/svdpage.cxx                   |    2 +-
 6 files changed, 9 insertions(+), 18 deletions(-)

New commits:
commit 4c17b9c33b5d8bee3bbc3f645d8dd2ed88198e88
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Thu Dec 26 15:38:24 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Jan 7 12:09:14 2025 +0100

    no need to allocate AnnotationData for every SdrObject
    
    SdrObject is performance sensitive, because we allocate a boatload
    of them when drawing charts. Avoiding an extra allocation that
    only a tiny handful of SdrObjects need is worthwhile.
    
    Change-Id: I4974bc1eacfe8abcce45ea659d9edaa8694135d5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179433
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179869

diff --git a/include/svx/annotation/ObjectAnnotationData.hxx 
b/include/svx/annotation/ObjectAnnotationData.hxx
index 4530df2fb61c..f7dc220d789d 100644
--- a/include/svx/annotation/ObjectAnnotationData.hxx
+++ b/include/svx/annotation/ObjectAnnotationData.hxx
@@ -19,9 +19,6 @@ namespace sdr::annotation
 class ObjectAnnotationData
 {
 public:
-    /// Does the (sdr) object represent an annotation
-    bool mbIsAnnotation : 1 = false;
-
     /// The annotation
     rtl::Reference<sdr::annotation::Annotation> mxAnnotation;
 
@@ -31,7 +28,7 @@ public:
     /// Open popup for the annotation
     void openPopup()
     {
-        if (mbIsAnnotation && mpAnnotationPopup)
+        if (mpAnnotationPopup)
             mpAnnotationPopup->openPopup();
     }
 };
diff --git a/include/svx/svdobj.hxx b/include/svx/svdobj.hxx
index d109c15f3ee3..927d0f55fba2 100644
--- a/include/svx/svdobj.hxx
+++ b/include/svx/svdobj.hxx
@@ -361,8 +361,8 @@ public:
     virtual bool IsDecorative() const;
 
     // Object representing an annotation
-    bool isAnnotationObject() const;
-    void setAsAnnotationObject(bool bSetAnnotation);
+    bool isAnnotationObject() const { return bool(mpAnnotationData); }
+    void setAsAnnotationObject();
     std::unique_ptr<sdr::annotation::ObjectAnnotationData>& 
getAnnotationData();
 
     // for group objects
diff --git a/sd/source/ui/annotations/annotationmanager.cxx 
b/sd/source/ui/annotations/annotationmanager.cxx
index 9d22ed38d735..ec876c667aaa 100644
--- a/sd/source/ui/annotations/annotationmanager.cxx
+++ b/sd/source/ui/annotations/annotationmanager.cxx
@@ -949,7 +949,7 @@ namespace
 
 void applyAnnotationCommon(SdrObject& rObject, 
rtl::Reference<sdr::annotation::Annotation> const& xAnnotation)
 {
-    rObject.setAsAnnotationObject(true);
+    rObject.setAsAnnotationObject();
     auto& xAnnotationData = rObject.getAnnotationData();
     xAnnotationData->mpAnnotationPopup.reset(new AnnotationPopup(xAnnotation));
     xAnnotationData->mxAnnotation = xAnnotation;
diff --git a/svx/source/annotation/AnnotationObject.cxx 
b/svx/source/annotation/AnnotationObject.cxx
index 55175ba90998..88e63d5565ad 100644
--- a/svx/source/annotation/AnnotationObject.cxx
+++ b/svx/source/annotation/AnnotationObject.cxx
@@ -139,7 +139,7 @@ AnnotationObject::AnnotationObject(SdrModel& rSdrModel, 
tools::Rectangle const&
 
 void AnnotationObject::setup()
 {
-    setAsAnnotationObject(true);
+    setAsAnnotationObject();
     mbTextFrame = true; // need this so the frame can be adjusted to the text
     bool bLOK = comphelper::LibreOfficeKit::isActive();
     SetVisible(getSdrModelFromSdrObject().IsPDFDocument() || !bLOK);
diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx
index 3d37873a52cc..4eb5146a0c0e 100644
--- a/svx/source/svdraw/svdobj.cxx
+++ b/svx/source/svdraw/svdobj.cxx
@@ -338,7 +338,6 @@ SdrObject::SdrObject(SdrModel& rSdrModel)
     : mpFillGeometryDefiningShape(nullptr)
     , mrSdrModelFromSdrObject(rSdrModel)
     , m_pUserCall(nullptr)
-    , mpAnnotationData(new sdr::annotation::ObjectAnnotationData)
     , mpImpl(new Impl)
     , mpParentOfSdrObject(nullptr)
     , m_nOrdNum(0)
@@ -374,7 +373,6 @@ SdrObject::SdrObject(SdrModel& rSdrModel, SdrObject const & 
rSource)
     : mpFillGeometryDefiningShape(nullptr)
     , mrSdrModelFromSdrObject(rSdrModel)
     , m_pUserCall(nullptr)
-    , mpAnnotationData(new sdr::annotation::ObjectAnnotationData)
     , mpImpl(new Impl)
     , mpParentOfSdrObject(nullptr)
     , m_nOrdNum(0)
@@ -854,14 +852,10 @@ bool SdrObject::IsDecorative() const
     return m_pPlusData == nullptr ? false : m_pPlusData->isDecorative;
 }
 
-bool SdrObject::isAnnotationObject() const
+void SdrObject::setAsAnnotationObject()
 {
-    return mpAnnotationData->mbIsAnnotation;
-}
-
-void SdrObject::setAsAnnotationObject(bool bSetAnnotation)
-{
-    mpAnnotationData->mbIsAnnotation = bSetAnnotation;
+    if (!mpAnnotationData)
+        mpAnnotationData = 
std::make_unique<sdr::annotation::ObjectAnnotationData>();
 }
 
 std::unique_ptr<sdr::annotation::ObjectAnnotationData>& 
SdrObject::getAnnotationData()
diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx
index bb82ecb9289e..e26a48fe039e 100644
--- a/svx/source/svdraw/svdpage.cxx
+++ b/svx/source/svdraw/svdpage.cxx
@@ -186,7 +186,7 @@ void SdrObjList::CopyObjects(const SdrObjList& rSrcList)
             aCloneList.AddPair(pSourceObject.get(), pTargetObject.get());
             if (pSourceObject->isAnnotationObject())
             {
-                pTargetObject->setAsAnnotationObject(true);
+                pTargetObject->setAsAnnotationObject();
                 pTargetObject->SetPrintable(false);
                 rtl::Reference<sdr::annotation::Annotation> xNewAnnotation;
                 SdrPage* pPage = pTargetObject->getSdrPageFromSdrObject();

Reply via email to