sw/inc/AnnotationWin.hxx                  |    3 +++
 sw/source/uibase/docvw/AnnotationWin2.cxx |   23 +++++++++++++++++------
 2 files changed, 20 insertions(+), 6 deletions(-)

New commits:
commit 8d18b5af883bb6b56e758801ee730a08bb88a8f5
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Jun 13 10:11:08 2023 +0200
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Tue Jun 13 17:11:45 2023 +0200

    speed up rendering annotatins, cache meta height
    
    shaves 2% off scrolling profile on a large word doc
    
    Change-Id: I283e3f99c1c385f3d20ea573d15ca59b4629c14d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152978
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sw/inc/AnnotationWin.hxx b/sw/inc/AnnotationWin.hxx
index 8499c392516a..c3d556085a03 100644
--- a/sw/inc/AnnotationWin.hxx
+++ b/sw/inc/AnnotationWin.hxx
@@ -29,6 +29,7 @@
 #include "postithelper.hxx"
 #include "swrect.hxx"
 #include "SidebarWindowsTypes.hxx"
+#include <optional>
 
 class EditView;
 class PopupMenu;
@@ -212,6 +213,7 @@ class SAL_DLLPUBLIC_RTTI SwAnnotationWin final : public 
InterimItemWindow
 
         virtual void    LoseFocus() override;
         virtual void    GetFocus() override;
+        virtual void    DataChanged( const DataChangedEvent& rDCEvt ) override;
 
         void        SetSizePixel( const Size& rNewSize ) override;
         SfxItemSet  DefaultItem();
@@ -280,6 +282,7 @@ class SAL_DLLPUBLIC_RTTI SwAnnotationWin final : public 
InterimItemWindow
         SwPostItField*       mpField;
 
         rtl::Reference<sw::sidebarwindows::SidebarWinAccessible> 
mxSidebarWinAccessible;
+        mutable std::optional<sal_Int32> moMetaHeight;
 };
 
 } // end of namespace sw::annotation
diff --git a/sw/source/uibase/docvw/AnnotationWin2.cxx 
b/sw/source/uibase/docvw/AnnotationWin2.cxx
index 06efbfdb581f..2c4bc7ce3d5e 100644
--- a/sw/source/uibase/docvw/AnnotationWin2.cxx
+++ b/sw/source/uibase/docvw/AnnotationWin2.cxx
@@ -1262,14 +1262,25 @@ int SwAnnotationWin::GetPrefScrollbarWidth() const
 
 sal_Int32 SwAnnotationWin::GetMetaHeight() const
 {
-    const int fields = GetNumFields();
+    if (!moMetaHeight)
+    {
+        const int fields = GetNumFields();
 
-    sal_Int32 nRequiredHeight = 0;
-    weld::Label* aLabels[3] = { mxMetadataAuthor.get(), mxMetadataDate.get(), 
mxMetadataResolved.get() };
-    for (int i = 0; i < fields; ++i)
-        nRequiredHeight += aLabels[i]->get_preferred_size().Height();
+        sal_Int32 nRequiredHeight = 0;
+        weld::Label* aLabels[3] = { mxMetadataAuthor.get(), 
mxMetadataDate.get(), mxMetadataResolved.get() };
+        for (int i = 0; i < fields; ++i)
+            nRequiredHeight += aLabels[i]->get_preferred_size().Height();
+        moMetaHeight = nRequiredHeight;
+    }
+    return *moMetaHeight;
+}
 
-    return nRequiredHeight;
+void SwAnnotationWin::DataChanged(const DataChangedEvent& rDCEvt)
+{
+    if ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) && 
(rDCEvt.GetFlags() & AllSettingsFlags::STYLE))
+    {
+        moMetaHeight.reset();
+    }
 }
 
 sal_Int32 SwAnnotationWin::GetNumFields() const

Reply via email to