include/unotools/eventcfg.hxx        |    3 +++
 sfx2/source/inc/eventsupplier.hxx    |    4 ++--
 sfx2/source/notify/eventsupplier.cxx |   14 +++++---------
 sfx2/source/notify/globalevents.cxx  |   12 +++++++-----
 unotools/source/config/eventcfg.cxx  |   12 +++++++-----
 5 files changed, 24 insertions(+), 21 deletions(-)

New commits:
commit ce214d56727ecf8fb212910a711b4e3ef38e4b63
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri May 13 15:30:37 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sat May 14 17:30:08 2022 +0200

    bypass some unnecessary wrapping in Any in SfxEvents_Impl
    
    Change-Id: I96d1194253207642e7abe83b0b18c82eb3782824
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134316
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/include/unotools/eventcfg.hxx b/include/unotools/eventcfg.hxx
index 5999d0bc1ea3..7ddca4a96be0 100644
--- a/include/unotools/eventcfg.hxx
+++ b/include/unotools/eventcfg.hxx
@@ -20,6 +20,7 @@
 #define INCLUDED_UNOTOOLS_EVENTCFG_HXX
 
 #include <unotools/unotoolsdllapi.h>
+#include <com/sun/star/beans/PropertyValue.hpp>
 #include <com/sun/star/document/XEventsSupplier.hpp>
 #include <com/sun/star/container/XNameReplace.hpp>
 #include <cppuhelper/implbase.hxx>
@@ -75,6 +76,8 @@ class UNOTOOLS_DLLPUBLIC GlobalEventConfig final :
         sal_Bool SAL_CALL hasElements(  ) override;
         static OUString GetEventName( GlobalEventId nID );
 
+        css::uno::Sequence < css::beans::PropertyValue > getByName2( const 
OUString& aName );
+
     private:
         static GlobalEventConfig_Impl* m_pImpl;
         static sal_Int32 m_nRefCount;
diff --git a/sfx2/source/inc/eventsupplier.hxx 
b/sfx2/source/inc/eventsupplier.hxx
index 0a6c1a971daf..56aa8f95e75f 100644
--- a/sfx2/source/inc/eventsupplier.hxx
+++ b/sfx2/source/inc/eventsupplier.hxx
@@ -44,7 +44,7 @@ class SvxMacro;
 class SfxEvents_Impl final : public ::cppu::WeakImplHelper< 
css::container::XNameReplace, css::document::XDocumentEventListener >
 {
     css::uno::Sequence< OUString >     maEventNames;
-    std::vector< css::uno::Any >       maEventData;
+    std::vector< css::uno::Sequence < css::beans::PropertyValue > >  
maEventData;
     css::uno::Reference< css::document::XDocumentEventBroadcaster >  
mxBroadcaster;
     std::mutex                     maMutex;
     SfxObjectShell                 *mpObjShell;
@@ -79,7 +79,7 @@ public:
                                     const ::comphelper::NamedValueCollection& 
i_eventDescriptor,
                                     ::comphelper::NamedValueCollection& 
o_normalizedDescriptor,
                                     SfxObjectShell* i_document );
-    static void Execute( css::uno::Any const & aEventData, const 
css::document::DocumentEvent& aTrigger, SfxObjectShell* pDoc );
+    static void Execute( css::uno::Sequence < css::beans::PropertyValue > 
const & aEventData, const css::document::DocumentEvent& aTrigger, 
SfxObjectShell* pDoc );
 
 private:
     /// Check if script URL whitelist exists, and if so, if current script url 
is part of it
diff --git a/sfx2/source/notify/eventsupplier.cxx 
b/sfx2/source/notify/eventsupplier.cxx
index 7ac2fd7d830d..d6bff98de8f0 100644
--- a/sfx2/source/notify/eventsupplier.cxx
+++ b/sfx2/source/notify/eventsupplier.cxx
@@ -98,11 +98,11 @@ void SAL_CALL SfxEvents_Impl::replaceByName( const OUString 
& aName, const uno::
 
     if ( !aNormalizedDescriptor.empty() )
     {
-        maEventData[nIndex] <<= aNormalizedDescriptor.getPropertyValues();
+        maEventData[nIndex] = aNormalizedDescriptor.getPropertyValues();
     }
     else
     {
-        maEventData[nIndex].clear();
+        maEventData[nIndex] = {};
     }
 }
 
@@ -117,7 +117,7 @@ uno::Any SAL_CALL SfxEvents_Impl::getByName( const 
OUString& aName )
 
     auto nIndex = comphelper::findValue(maEventNames, aName);
     if (nIndex != -1)
-        return maEventData[nIndex];
+        return uno::Any(maEventData[nIndex]);
 
     throw container::NoSuchElementException();
 }
@@ -180,12 +180,8 @@ bool SfxEvents_Impl::isScriptURLAllowed(const OUString& 
aScriptURL)
     return false;
 }
 
-void SfxEvents_Impl::Execute( uno::Any const & aEventData, const 
document::DocumentEvent& aTrigger, SfxObjectShell* pDoc )
+void SfxEvents_Impl::Execute( css::uno::Sequence < css::beans::PropertyValue > 
const & aProperties, const document::DocumentEvent& aTrigger, SfxObjectShell* 
pDoc )
 {
-    uno::Sequence < beans::PropertyValue > aProperties;
-    if ( !(aEventData >>= aProperties) )
-        return;
-
     OUString aType;
     OUString aScript;
     OUString aLibrary;
@@ -292,7 +288,7 @@ void SAL_CALL SfxEvents_Impl::documentEventOccured( const 
document::DocumentEven
     if ( nIndex == -1 )
         return;
 
-    uno::Any aEventData = maEventData[ nIndex ];
+    css::uno::Sequence < css::beans::PropertyValue > aEventData = maEventData[ 
nIndex ];
     aGuard.unlock();
     Execute( aEventData, aEvent, mpObjShell );
 }
diff --git a/sfx2/source/notify/globalevents.cxx 
b/sfx2/source/notify/globalevents.cxx
index 87564e74ed65..cd6b08007115 100644
--- a/sfx2/source/notify/globalevents.cxx
+++ b/sfx2/source/notify/globalevents.cxx
@@ -35,6 +35,7 @@
 #include <comphelper/interfacecontainer4.hxx>
 #include <cppuhelper/supportsservice.hxx>
 #include <comphelper/enumhelper.hxx>
+#include <rtl/ref.hxx>
 #include <sfx2/app.hxx>
 #include <tools/diagnose_ex.h>
 #include <unotools/eventcfg.hxx>
@@ -60,7 +61,7 @@ class SfxGlobalEvents_Impl : public ::cppu::WeakImplHelper< 
css::lang::XServiceI
                                                             >
 {
     std::mutex m_aLock;
-    css::uno::Reference< css::container::XNameReplace > m_xEvents;
+    rtl::Reference< GlobalEventConfig > m_xEvents;
     css::uno::Reference< css::document::XEventListener > 
m_xJobExecutorListener;
     ::comphelper::OInterfaceContainerHelper4<document::XEventListener> 
m_aLegacyListeners;
     ::comphelper::OInterfaceContainerHelper4<document::XDocumentEventListener> 
m_aDocumentListeners;
@@ -448,7 +449,7 @@ void SfxGlobalEvents_Impl::implts_notifyJobExecution(const 
document::EventObject
 
 void SfxGlobalEvents_Impl::implts_checkAndExecuteEventBindings(const 
document::DocumentEvent& aEvent)
 {
-    css::uno::Reference<css::container::XNameReplace> events;
+    rtl::Reference<GlobalEventConfig> events;
     {
         std::scoped_lock g(m_aLock);
         events = m_xEvents;
@@ -458,10 +459,11 @@ void 
SfxGlobalEvents_Impl::implts_checkAndExecuteEventBindings(const document::D
     }
     try
     {
-        uno::Any aAny;
         if ( events->hasByName( aEvent.EventName ) )
-            aAny = events->getByName(aEvent.EventName);
-        SfxEvents_Impl::Execute(aAny, aEvent, nullptr);
+        {
+            uno::Sequence < beans::PropertyValue > aAny = 
events->getByName2(aEvent.EventName);
+            SfxEvents_Impl::Execute(aAny, aEvent, nullptr);
+        }
     }
     catch ( uno::RuntimeException const & )
     {
diff --git a/unotools/source/config/eventcfg.cxx 
b/unotools/source/config/eventcfg.cxx
index 0c0f87ed4624..fb1eb948a47b 100644
--- a/unotools/source/config/eventcfg.cxx
+++ b/unotools/source/config/eventcfg.cxx
@@ -111,7 +111,7 @@ public:
     /// @throws css::container::NoSuchElementException
     /// @throws css::lang::WrappedTargetException
     /// @throws css::uno::RuntimeException
-    css::uno::Any getByName( const OUString& aName );
+    css::uno::Sequence < css::beans::PropertyValue > getByName( const 
OUString& aName );
     /// @throws css::uno::RuntimeException
     css::uno::Sequence< OUString > getElementNames(  );
     /// @throws css::uno::RuntimeException
@@ -238,9 +238,8 @@ void GlobalEventConfig_Impl::replaceByName( const OUString& 
aName, const Any& aE
     SetModified();
 }
 
-Any GlobalEventConfig_Impl::getByName( const OUString& aName )
+css::uno::Sequence < css::beans::PropertyValue > 
GlobalEventConfig_Impl::getByName( const OUString& aName )
 {
-    Any aRet;
     Sequence< beans::PropertyValue > props(2);
     auto pProps = props.getArray();
     pProps[0].Name = "EventType";
@@ -261,8 +260,7 @@ Any GlobalEventConfig_Impl::getByName( const OUString& 
aName )
 
         pProps[1].Value <<= OUString();
     }
-    aRet <<= props;
-    return aRet;
+    return props;
 }
 
 Sequence< OUString > GlobalEventConfig_Impl::getElementNames(  )
@@ -341,6 +339,10 @@ void SAL_CALL GlobalEventConfig::replaceByName( const 
OUString& aName, const Any
     m_pImpl->replaceByName( aName, aElement );
 }
 Any SAL_CALL GlobalEventConfig::getByName( const OUString& aName )
+{
+    return Any(getByName2(aName));
+}
+css::uno::Sequence < css::beans::PropertyValue > 
GlobalEventConfig::getByName2( const OUString& aName )
 {
     std::unique_lock aGuard( GetOwnStaticMutex() );
     return m_pImpl->getByName( aName );

Reply via email to