[Libreoffice-commits] core.git: 2 commits - compilerplugins/clang svx/source

2023-06-03 Thread Szymon Kłos (via logerrit)
 compilerplugins/clang/badstatics.cxx|1 
 svx/source/inc/StylesPreviewWindow.hxx  |1 
 svx/source/tbxctrls/StylesPreviewWindow.cxx |   66 +---
 3 files changed, 61 insertions(+), 7 deletions(-)

New commits:
commit d8b834a750a284ecd04cac1f4de4cb9cbf05c42c
Author: Szymon Kłos 
AuthorDate: Fri Jun 2 18:31:55 2023 +0200
Commit: Caolán McNamara 
CommitDate: Sat Jun 3 17:44:01 2023 +0200

Styles preview cache cleanup on exit

Change-Id: I28929d4137008ebcca1733837d0b2112b6859a89
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152563
Reviewed-by: Caolán McNamara 
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Szymon Kłos 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152576
Tested-by: Jenkins

diff --git a/compilerplugins/clang/badstatics.cxx 
b/compilerplugins/clang/badstatics.cxx
index 7c604bc5ee66..f22dabac9b48 100644
--- a/compilerplugins/clang/badstatics.cxx
+++ b/compilerplugins/clang/badstatics.cxx
@@ -199,9 +199,8 @@ public:
 || name == "g_aWindowList"
 //vcl/unx/gtk3/a11y/atkutil.cxx, asserted empty at exit
 || name == "gFontPreviewVirDevs"
-|| (loplugin::DeclCheck(pVarDecl).Var("aPreviewCache")
-.Class("StylesPreviewWindow_Base").GlobalNamespace()) // 
TODO: temp disable
 //svtools/source/control/ctrlbox.cxx, empty at exit
+|| name == "gStylePreviewCache" // 
svx/source/tbxctrls/StylesPreviewWindow.cxx
 || name == "aLogger" // FormulaLogger& FormulaLogger::get() in 
sc/source/core/tool/formulalogger.cxx
 || name == "s_aUncommittedRegistrations" // 
sw/source/uibase/dbui/dbmgr.cxx
 || (loplugin::DeclCheck(pVarDecl).Var("aAllListeners")
diff --git a/svx/source/inc/StylesPreviewWindow.hxx 
b/svx/source/inc/StylesPreviewWindow.hxx
index 47e21dcb4ca0..de4984e35968 100644
--- a/svx/source/inc/StylesPreviewWindow.hxx
+++ b/svx/source/inc/StylesPreviewWindow.hxx
@@ -127,8 +127,6 @@ private:
 void UpdateStylesList();
 void UpdateSelection();
 bool Command(const CommandEvent& rEvent);
-
-static std::map> aPreviewCache;
 };
 
 class StylesPreviewWindow_Impl final : public InterimItemWindow, public 
StylesPreviewWindow_Base
diff --git a/svx/source/tbxctrls/StylesPreviewWindow.cxx 
b/svx/source/tbxctrls/StylesPreviewWindow.cxx
index c1e3549fb54a..a51283d0d750 100644
--- a/svx/source/tbxctrls/StylesPreviewWindow.cxx
+++ b/svx/source/tbxctrls/StylesPreviewWindow.cxx
@@ -60,7 +60,36 @@
 
 #include 
 
-std::map> 
StylesPreviewWindow_Base::aPreviewCache;
+namespace
+{
+class StylePreviewCache
+{
+static std::map> gStylePreviewCache;
+static int gStylePreviewCacheClients;
+
+public:
+static std::map>& Get() { return 
gStylePreviewCache; }
+
+static void ClearCache()
+{
+for (auto& aPreview : gStylePreviewCache)
+aPreview.second.disposeAndClear();
+
+gStylePreviewCache.clear();
+}
+
+static void RegisterClient() { gStylePreviewCacheClients++; }
+static void UnregisterClient()
+{
+gStylePreviewCacheClients--;
+if (!gStylePreviewCacheClients)
+ClearCache();
+}
+};
+
+std::map> 
StylePreviewCache::gStylePreviewCache;
+int StylePreviewCache::gStylePreviewCacheClients;
+}
 
 StyleStatusListener::StyleStatusListener(
 StylesPreviewWindow_Base* pPreviewControl,
@@ -103,8 +132,10 @@ StylePoolChangeListener::~StylePoolChangeListener()
 EndListening(*m_pStyleSheetPool);
 }
 
-void StylePoolChangeListener::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& 
/*rHint*/)
+void StylePoolChangeListener::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& 
rHint)
 {
+if (rHint.GetId() == SfxHintId::StyleSheetModified)
+StylePreviewCache::ClearCache();
 m_pPreviewControl->RequestStylesListUpdate();
 }
 
@@ -378,6 +409,8 @@ StylesPreviewWindow_Base::StylesPreviewWindow_Base(
 , m_aUpdateTask(*this)
 , m_aDefaultStyles(std::move(aDefaultStyles))
 {
+StylePreviewCache::RegisterClient();
+
 m_xStylesView->connect_selection_changed(LINK(this, 
StylesPreviewWindow_Base, Selected));
 m_xStylesView->connect_item_activated(LINK(this, StylesPreviewWindow_Base, 
DoubleClick));
 m_xStylesView->connect_command(LINK(this, StylesPreviewWindow_Base, 
DoCommand));
@@ -424,6 +457,8 @@ StylesPreviewWindow_Base::~StylesPreviewWindow_Base()
 
 m_aUpdateTask.Stop();
 
+StylePreviewCache::UnregisterClient();
+
 try
 {
 m_xStatusListener->dispose();
@@ -465,8 +500,9 @@ void StylesListUpdateTask::Invoke()
 VclPtr
 StylesPreviewWindow_Base::GetCachedPreview(const std::pair& rStyle)
 {
-if (aPreviewCache.find(rStyle.second) != aPreviewCache.end())
-return aPreviewCache[rStyle.second];
+auto aFound = StylePreviewCache::Get().find(rStyle.second);
+if (aFound != StylePreviewCache::Get().end())
+

[Libreoffice-commits] core.git: 2 commits - compilerplugins/clang svx/source

2019-11-30 Thread Noel Grandin (via logerrit)
 compilerplugins/clang/mergeclasses.py  |4 
 compilerplugins/clang/mergeclasses.results |  196 +++--
 svx/source/form/fmscriptingenv.cxx |   54 ---
 svx/source/form/fmundo.cxx |2 
 svx/source/inc/fmscriptingenv.hxx  |   35 +++--
 svx/source/inc/fmundo.hxx  |2 
 6 files changed, 161 insertions(+), 132 deletions(-)

New commits:
commit 6b6609fc03d484ce1bfb18162b709704049b5ee9
Author: Noel Grandin 
AuthorDate: Fri Nov 29 15:21:51 2019 +0200
Commit: Noel Grandin 
CommitDate: Sat Nov 30 21:33:48 2019 +0100

loplugin:mergeclasses FormScriptingEnvironment with 
IFormScriptingEnvironment

Change-Id: I334ad78681e2b7389388316881fd9f57455e875f
Reviewed-on: https://gerrit.libreoffice.org/84109
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/svx/source/form/fmscriptingenv.cxx 
b/svx/source/form/fmscriptingenv.cxx
index f76f8e86f729..aa480dd3a123 100644
--- a/svx/source/form/fmscriptingenv.cxx
+++ b/svx/source/form/fmscriptingenv.cxx
@@ -71,19 +71,11 @@ namespace svxform
 using ::com::sun::star::awt::XControl;
 using ::com::sun::star::beans::XPropertySet;
 
-namespace {
-
-class FormScriptingEnvironment;
-
-}
-
 //= FormScriptListener
 
 typedef ::cppu::WeakImplHelper <   XScriptListener
 >   FormScriptListener_Base;
 
-namespace {
-
 /** implements the XScriptListener interface, is used by 
FormScriptingEnvironment
 */
 class FormScriptListener:public FormScriptListener_Base
@@ -145,37 +137,6 @@ namespace svxform
 DECL_LINK( OnAsyncScriptEvent, void*, void );
 };
 
-class FormScriptingEnvironment:
-public IFormScriptingEnvironment
-{
-private:
-typedef rtl::Reference ListenerImplementation;
-
-private:
-::osl::Mutexm_aMutex;
-ListenerImplementation  m_pScriptListener;
-FmFormModel&m_rFormModel;
-boolm_bDisposed;
-
-public:
-explicit FormScriptingEnvironment( FmFormModel& _rModel );
-FormScriptingEnvironment(const FormScriptingEnvironment&) = delete;
-FormScriptingEnvironment& operator=(const FormScriptingEnvironment&) = 
delete;
-
-// callback for FormScriptListener
-void doFireScriptEvent( const ScriptEvent& _rEvent, Any* 
_pSynchronousResult );
-
-// IFormScriptingEnvironment
-virtual void registerEventAttacherManager( const Reference< 
XEventAttacherManager >& _rxManager ) override;
-virtual void revokeEventAttacherManager( const Reference< 
XEventAttacherManager >& _rxManager ) override;
-virtual void dispose() override;
-
-private:
-void impl_registerOrRevoke_throw( const Reference< 
XEventAttacherManager >& _rxManager, bool _bRegister );
-};
-
-}
-
 FormScriptListener::FormScriptListener( FormScriptingEnvironment* 
pScriptExecutor )
 :m_pScriptExecutor( pScriptExecutor )
 {
@@ -906,7 +867,7 @@ namespace svxform
 :m_rFormModel( _rModel )
 ,m_bDisposed( false )
 {
-m_pScriptListener = ListenerImplementation( new FormScriptListener( 
this ) );
+m_pScriptListener = new FormScriptListener( this );
 // note that this is a cyclic reference between the FormScriptListener 
and the FormScriptingEnvironment
 // This cycle is broken up when our instance is disposed.
 }
@@ -946,12 +907,6 @@ namespace svxform
 impl_registerOrRevoke_throw( _rxManager, false );
 }
 
-
-IFormScriptingEnvironment::~IFormScriptingEnvironment()
-{
-}
-
-
 namespace
 {
 class NewStyleUNOScript
@@ -1080,13 +1035,6 @@ namespace svxform
 m_pScriptListener.clear();
 }
 
-
-PFormScriptingEnvironment createDefaultFormScriptingEnvironment( 
FmFormModel& _rModel )
-{
-return new FormScriptingEnvironment( _rModel );
-}
-
-
 }
 
 
diff --git a/svx/source/form/fmundo.cxx b/svx/source/form/fmundo.cxx
index 2552161a43f9..d887bbad661f 100644
--- a/svx/source/form/fmundo.cxx
+++ b/svx/source/form/fmundo.cxx
@@ -177,7 +177,7 @@ static OUString static_STR_UNDO_PROPERTY;
 FmXUndoEnvironment::FmXUndoEnvironment(FmFormModel& _rModel)
:rModel( _rModel )
,m_pPropertySetCache( nullptr )
-   ,m_pScriptingEnv( 
::svxform::createDefaultFormScriptingEnvironment( _rModel ) )
+   ,m_pScriptingEnv( new svxform::FormScriptingEnvironment( 
_rModel ) )
,m_Locks( 0 )
,bReadOnly( false )
,m_bDisposed( false )
diff --git a/svx/source/inc/fmscriptingenv.hxx 
b/svx/source/inc/fmscriptingenv.hxx
index d747f038e844..ef4f29f80418 100644
--- a/svx/source/inc/fmscriptingenv.hxx
+++ b/svx/source/inc/fmscriptingenv.hxx
@@ -28,16 +28,21 @@ class FmFormModel;
 
 namespace svxform
 {
-
+class