comphelper/source/misc/simplefileaccessinteraction.cxx |   12 ++-
 comphelper/source/misc/stillreadwriteinteraction.cxx   |   61 ++++++++---------
 include/comphelper/stillreadwriteinteraction.hxx       |    6 -
 include/ucbhelper/interceptedinteraction.hxx           |   26 +++----
 ucbhelper/source/client/interceptedinteraction.cxx     |    8 +-
 unotools/source/misc/mediadescriptor.cxx               |    1 
 6 files changed, 55 insertions(+), 59 deletions(-)

New commits:
commit e3c961e6a3917d95534652e0f982918cc1079015
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Mon Oct 2 10:25:46 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Mon Oct 2 13:07:00 2023 +0200

    reduce allocations in InterceptedInteraction
    
    the list of intercepted interactions is static per sub-class, so just
    pass up a o3tl::span at constructor time.
    
    Change-Id: Ib45c5a3338e0eb3848486dfc707052f07492eb61
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157480
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/comphelper/source/misc/simplefileaccessinteraction.cxx 
b/comphelper/source/misc/simplefileaccessinteraction.cxx
index 8cd77af7d693..f7a4f0eab237 100644
--- a/comphelper/source/misc/simplefileaccessinteraction.cxx
+++ b/comphelper/source/misc/simplefileaccessinteraction.cxx
@@ -29,10 +29,9 @@ const sal_Int32 HANDLE_CERTIFICATEREQUEST = 3;
 /// Will handle com::sun::star::ucb::AuthenticationRequest
 const sal_Int32 HANDLE_AUTHENTICATIONREQUEST = 4;
 
-SimpleFileAccessInteraction::SimpleFileAccessInteraction(
-    const css::uno::Reference<css::task::XInteractionHandler>& xHandler)
+static o3tl::span<const 
::ucbhelper::InterceptedInteraction::InterceptedRequest> getInterceptions()
 {
-    std::vector<::ucbhelper::InterceptedInteraction::InterceptedRequest> 
lInterceptions{
+    static const ::ucbhelper::InterceptedInteraction::InterceptedRequest 
lInterceptions[]{
         { //intercept standard IO error exception (local file and WebDAV)
           css::uno::Any(css::ucb::InteractiveIOException()),
           cppu::UnoType<css::task::XInteractionAbort>::get(), 
HANDLE_INTERACTIVEIOEXCEPTION },
@@ -52,9 +51,14 @@ SimpleFileAccessInteraction::SimpleFileAccessInteraction(
           css::uno::Any(css::ucb::AuthenticationRequest()),
           cppu::UnoType<css::task::XInteractionApprove>::get(), 
HANDLE_AUTHENTICATIONREQUEST }
     };
+    return lInterceptions;
+}
 
+SimpleFileAccessInteraction::SimpleFileAccessInteraction(
+    const css::uno::Reference<css::task::XInteractionHandler>& xHandler)
+    : InterceptedInteraction(getInterceptions())
+{
     setInterceptedHandler(xHandler);
-    setInterceptions(std::move(lInterceptions));
 }
 
 SimpleFileAccessInteraction::~SimpleFileAccessInteraction() {}
diff --git a/comphelper/source/misc/stillreadwriteinteraction.cxx 
b/comphelper/source/misc/stillreadwriteinteraction.cxx
index 88bc25bc46cb..a6d1db057745 100644
--- a/comphelper/source/misc/stillreadwriteinteraction.cxx
+++ b/comphelper/source/misc/stillreadwriteinteraction.cxx
@@ -34,43 +34,42 @@
 
 namespace comphelper{
 
+const sal_Int32 HANDLE_INTERACTIVEIOEXCEPTION       = 0;
+const sal_Int32 HANDLE_UNSUPPORTEDDATASINKEXCEPTION = 1;
+const sal_Int32 HANDLE_AUTHENTICATIONREQUESTEXCEPTION = 2;
+const sal_Int32 HANDLE_CERTIFICATEVALIDATIONREQUESTEXCEPTION = 3;
+
+static o3tl::span<const 
::ucbhelper::InterceptedInteraction::InterceptedRequest> getInterceptions()
+{
+    static const ::ucbhelper::InterceptedInteraction::InterceptedRequest 
lInterceptions[] {
+        {
+          css::uno::Any(css::ucb::InteractiveIOException()),
+          cppu::UnoType<css::task::XInteractionAbort>::get(), 
HANDLE_INTERACTIVEIOEXCEPTION
+        },
+        {
+          css::uno::Any(css::ucb::UnsupportedDataSinkException()),
+          cppu::UnoType<css::task::XInteractionAbort>::get(), 
HANDLE_UNSUPPORTEDDATASINKEXCEPTION
+        },
+        {
+          css::uno::Any(css::ucb::AuthenticationRequest()),
+          cppu::UnoType<css::task::XInteractionApprove>::get(), 
HANDLE_AUTHENTICATIONREQUESTEXCEPTION
+        },
+        {
+          css::uno::Any(css::ucb::CertificateValidationRequest()),
+          cppu::UnoType<css::task::XInteractionApprove>::get(), 
HANDLE_CERTIFICATEVALIDATIONREQUESTEXCEPTION
+        },
+    };
+    return lInterceptions;
+}
+
 StillReadWriteInteraction::StillReadWriteInteraction(const 
css::uno::Reference< css::task::XInteractionHandler >& xHandler,
                                                      css::uno::Reference< 
css::task::XInteractionHandler > xAuxiliaryHandler)
-             : m_bUsed                    (false)
+             : InterceptedInteraction(getInterceptions())
+             , m_bUsed                    (false)
              , m_bHandledByMySelf         (false)
              , m_xAuxiliaryHandler(std::move(xAuxiliaryHandler))
 {
-    std::vector< ::ucbhelper::InterceptedInteraction::InterceptedRequest > 
lInterceptions;
-    lInterceptions.reserve(4);
-    ::ucbhelper::InterceptedInteraction::InterceptedRequest                  
aInterceptedRequest;
-
-    aInterceptedRequest.Handle = HANDLE_INTERACTIVEIOEXCEPTION;
-    aInterceptedRequest.Request <<= css::ucb::InteractiveIOException();
-    aInterceptedRequest.Continuation = 
cppu::UnoType<css::task::XInteractionAbort>::get();
-    lInterceptions.push_back(aInterceptedRequest);
-
-    aInterceptedRequest.Handle = HANDLE_UNSUPPORTEDDATASINKEXCEPTION;
-    aInterceptedRequest.Request <<= css::ucb::UnsupportedDataSinkException();
-    aInterceptedRequest.Continuation = 
cppu::UnoType<css::task::XInteractionAbort>::get();
-    lInterceptions.push_back(aInterceptedRequest);
-
-    aInterceptedRequest.Handle = HANDLE_AUTHENTICATIONREQUESTEXCEPTION;
-    aInterceptedRequest.Request <<= css::ucb::AuthenticationRequest();
-    aInterceptedRequest.Continuation = 
cppu::UnoType<css::task::XInteractionApprove>::get();
-    lInterceptions.push_back(aInterceptedRequest);
-
-    aInterceptedRequest.Handle = HANDLE_CERTIFICATEVALIDATIONREQUESTEXCEPTION;
-    aInterceptedRequest.Request <<= css::ucb::CertificateValidationRequest();
-    aInterceptedRequest.Continuation = 
cppu::UnoType<css::task::XInteractionApprove>::get();
-    lInterceptions.push_back(aInterceptedRequest);
-
     setInterceptedHandler(xHandler);
-    setInterceptions(std::move(lInterceptions));
-}
-
-void StillReadWriteInteraction::resetInterceptions()
-{
-    setInterceptions(std::vector< 
::ucbhelper::InterceptedInteraction::InterceptedRequest >());
 }
 
 void StillReadWriteInteraction::resetErrorStates()
diff --git a/include/comphelper/stillreadwriteinteraction.hxx 
b/include/comphelper/stillreadwriteinteraction.hxx
index fb03a7ad1d84..6347e03f47c3 100644
--- a/include/comphelper/stillreadwriteinteraction.hxx
+++ b/include/comphelper/stillreadwriteinteraction.hxx
@@ -33,11 +33,6 @@ namespace comphelper{
 class UNLESS_MERGELIBS(COMPHELPER_DLLPUBLIC) StillReadWriteInteraction final : 
public ::ucbhelper::InterceptedInteraction
 {
 private:
-    static const sal_Int32 HANDLE_INTERACTIVEIOEXCEPTION       = 0;
-    static const sal_Int32 HANDLE_UNSUPPORTEDDATASINKEXCEPTION = 1;
-    static const sal_Int32 HANDLE_AUTHENTICATIONREQUESTEXCEPTION = 2;
-    static const sal_Int32 HANDLE_CERTIFICATEVALIDATIONREQUESTEXCEPTION = 3;
-
     bool m_bUsed;
     bool m_bHandledByMySelf;
 
@@ -45,7 +40,6 @@ public:
     StillReadWriteInteraction(const css::uno::Reference< 
css::task::XInteractionHandler >& xHandler,
                               css::uno::Reference< 
css::task::XInteractionHandler > xAuxiliaryHandler);
 
-    void resetInterceptions();
     void resetErrorStates();
     bool wasWriteError() const { return (m_bUsed && m_bHandledByMySelf);}
 
diff --git a/include/ucbhelper/interceptedinteraction.hxx 
b/include/ucbhelper/interceptedinteraction.hxx
index 78344c319903..15000deb81d5 100644
--- a/include/ucbhelper/interceptedinteraction.hxx
+++ b/include/ucbhelper/interceptedinteraction.hxx
@@ -26,6 +26,7 @@
 
 #include <cppuhelper/implbase.hxx>
 #include <ucbhelper/ucbhelperdllapi.h>
+#include <o3tl/span.hxx>
 
 namespace com::sun::star::task { class XInteractionRequest; }
 
@@ -129,7 +130,7 @@ class UCBHELPER_DLLPUBLIC InterceptedInteraction : public 
InterceptedInteraction
 
         /** @short  these list contains the requests, which should be 
intercepted.
          */
-        ::std::vector< InterceptedRequest > m_lInterceptions;
+        o3tl::span< const InterceptedRequest > m_lInterceptions;
 
 
     // native interface
@@ -140,6 +141,17 @@ class UCBHELPER_DLLPUBLIC InterceptedInteraction : public 
InterceptedInteraction
          */
         InterceptedInteraction();
 
+        /** @short  initialise with a list of intercepted interactions.
+
+            @attention  If the interface method handle() will be overwritten by
+                        a derived class, the functionality behind these static 
list
+                        can't be used.
+
+            @param  lInterceptions
+                    the list of intercepted requests.
+         */
+        InterceptedInteraction(o3tl::span< const InterceptedRequest > 
m_lInterceptions);
+
 
         /** @short  initialize a new instance with the interaction handler,
                     which should be intercepted.
@@ -155,18 +167,6 @@ class UCBHELPER_DLLPUBLIC InterceptedInteraction : public 
InterceptedInteraction
         void setInterceptedHandler(const css::uno::Reference< 
css::task::XInteractionHandler >& xInterceptedHandler);
 
 
-        /** @short  set a new list of intercepted interactions.
-
-            @attention  If the interface method handle() will be overwritten by
-                        a derived class, the functionality behind these static 
list
-                        can't be used.
-
-            @param  lInterceptions
-                    the list of intercepted requests.
-         */
-        void setInterceptions(::std::vector< InterceptedRequest >&& 
lInterceptions);
-
-
         /** @short  extract a requested continuation from the list of 
available ones.
 
             @param  lContinuations
diff --git a/ucbhelper/source/client/interceptedinteraction.cxx 
b/ucbhelper/source/client/interceptedinteraction.cxx
index 96b3fd32cb41..a6a7fe11806e 100644
--- a/ucbhelper/source/client/interceptedinteraction.cxx
+++ b/ucbhelper/source/client/interceptedinteraction.cxx
@@ -27,14 +27,14 @@ InterceptedInteraction::InterceptedInteraction()
 {
 }
 
-void InterceptedInteraction::setInterceptedHandler(const css::uno::Reference< 
css::task::XInteractionHandler >& xInterceptedHandler)
+InterceptedInteraction::InterceptedInteraction(o3tl::span< const 
InterceptedRequest > lInterceptions)
+    : m_lInterceptions(lInterceptions)
 {
-    m_xInterceptedHandler = xInterceptedHandler;
 }
 
-void InterceptedInteraction::setInterceptions(::std::vector< 
InterceptedRequest >&& lInterceptions)
+void InterceptedInteraction::setInterceptedHandler(const css::uno::Reference< 
css::task::XInteractionHandler >& xInterceptedHandler)
 {
-    m_lInterceptions = std::move(lInterceptions);
+    m_xInterceptedHandler = xInterceptedHandler;
 }
 
 InterceptedInteraction::EInterceptionState InterceptedInteraction::intercepted(
diff --git a/unotools/source/misc/mediadescriptor.cxx 
b/unotools/source/misc/mediadescriptor.cxx
index b8bb7f13469e..d4567c467052 100644
--- a/unotools/source/misc/mediadescriptor.cxx
+++ b/unotools/source/misc/mediadescriptor.cxx
@@ -459,7 +459,6 @@ bool MediaDescriptor::impl_openStreamWithURL( const 
OUString& sURL, bool bLockFi
         if ( bReadOnly )
                (*this)[MediaDescriptor::PROP_READONLY] <<= bReadOnly;
 
-        xInteraction->resetInterceptions();
         xInteraction->resetErrorStates();
         try
         {

Reply via email to