embeddedobj/source/commonembedding/embedobj.cxx |   72 +++++++++++++++++++++---
 embeddedobj/source/commonembedding/miscobj.cxx  |   36 ------------
 embeddedobj/source/inc/commonembobj.hxx         |    2 
 3 files changed, 64 insertions(+), 46 deletions(-)

New commits:
commit c59ede12ff06f7c10670d9ea8a631b25237e9f02
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Mon May 23 17:18:32 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue May 24 08:07:49 2022 +0200

    this data does not need to be per-object
    
    Change-Id: I7cf9486d80be103c2e9affd805c7bdac46fafe9a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134838
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/embeddedobj/source/commonembedding/embedobj.cxx 
b/embeddedobj/source/commonembedding/embedobj.cxx
index 240112b2483e..0b1cb5785dac 100644
--- a/embeddedobj/source/commonembedding/embedobj.cxx
+++ b/embeddedobj/source/commonembedding/embedobj.cxx
@@ -48,6 +48,7 @@
 #include <commonembobj.hxx>
 #include "embedobj.hxx"
 #include <specialobject.hxx>
+#include <array>
 
 using namespace ::com::sun::star;
 
@@ -71,6 +72,60 @@ awt::Rectangle GetRectangleInterception( const 
awt::Rectangle& aRect1, const awt
     return aResult;
 }
 
+namespace
+{
+    using IntermediateStatesMap = std::array<std::array<uno::Sequence< 
sal_Int32 >, NUM_SUPPORTED_STATES>, NUM_SUPPORTED_STATES>;
+    const IntermediateStatesMap & getIntermediateStatesMap()
+    {
+        static const IntermediateStatesMap map = [] () {
+            IntermediateStatesMap tmp;
+
+            // intermediate states
+            // In the following table the first index points to starting state,
+            // the second one to the target state, and the sequence referenced 
by
+            // first two indexes contains intermediate states, that should be
+            // passed by object to reach the target state.
+            // If the sequence is empty that means that indirect switch from 
start
+            // state to the target state is forbidden, only if direct switch 
is possible
+            // the state can be reached.
+
+            tmp[0][2] = { embed::EmbedStates::RUNNING };
+
+            tmp[0][3] = { embed::EmbedStates::RUNNING,
+                                                
embed::EmbedStates::INPLACE_ACTIVE };
+
+            tmp[0][4] = {embed::EmbedStates::RUNNING};
+
+            tmp[1][3] = { embed::EmbedStates::INPLACE_ACTIVE };
+
+            tmp[2][0] = { embed::EmbedStates::RUNNING };
+
+            tmp[3][0] = { embed::EmbedStates::INPLACE_ACTIVE,
+                                                embed::EmbedStates::RUNNING };
+
+            tmp[3][1] = { embed::EmbedStates::INPLACE_ACTIVE };
+
+            tmp[4][0] = { embed::EmbedStates::RUNNING };
+
+            return tmp;
+        }();
+        return map;
+    }
+
+    // accepted states
+    const css::uno::Sequence< sal_Int32 > & getAcceptedStates()
+    {
+        static const css::uno::Sequence< sal_Int32 > states {
+            /* [0] */ embed::EmbedStates::LOADED,
+                          /* [1] */ embed::EmbedStates::RUNNING,
+                          /* [2] */ embed::EmbedStates::INPLACE_ACTIVE,
+                          /* [3] */ embed::EmbedStates::UI_ACTIVE,
+                          /* [4] */ embed::EmbedStates::ACTIVE };
+        assert(states.getLength() == NUM_SUPPORTED_STATES);
+        return states;
+    }
+
+}
 
 sal_Int32 OCommonEmbeddedObject::ConvertVerbToState_Impl( sal_Int32 nVerb )
 {
@@ -389,27 +444,28 @@ void OCommonEmbeddedObject::SwitchStateTo_Impl( sal_Int32 
nNextState )
 uno::Sequence< sal_Int32 > const & 
OCommonEmbeddedObject::GetIntermediateStatesSequence_Impl( sal_Int32 nNewState )
 {
     sal_Int32 nCurInd = 0;
-    for ( nCurInd = 0; nCurInd < m_aAcceptedStates.getLength(); nCurInd++ )
-        if ( m_aAcceptedStates[nCurInd] == m_nObjectState )
+    auto & rAcceptedStates = getAcceptedStates();
+    for ( nCurInd = 0; nCurInd < rAcceptedStates.getLength(); nCurInd++ )
+        if ( rAcceptedStates[nCurInd] == m_nObjectState )
             break;
 
-    if ( nCurInd == m_aAcceptedStates.getLength() )
+    if ( nCurInd == rAcceptedStates.getLength() )
         throw embed::WrongStateException( "The object is in unacceptable 
state!",
                                           static_cast< ::cppu::OWeakObject* 
>(this) );
 
     sal_Int32 nDestInd = 0;
-    for ( nDestInd = 0; nDestInd < m_aAcceptedStates.getLength(); nDestInd++ )
-        if ( m_aAcceptedStates[nDestInd] == nNewState )
+    for ( nDestInd = 0; nDestInd < rAcceptedStates.getLength(); nDestInd++ )
+        if ( rAcceptedStates[nDestInd] == nNewState )
             break;
 
-    if ( nDestInd == m_aAcceptedStates.getLength() )
+    if ( nDestInd == rAcceptedStates.getLength() )
         throw embed::UnreachableStateException(
             "The state either not reachable, or the object allows the state 
only as an intermediate one!",
             static_cast< ::cppu::OWeakObject* >(this),
             m_nObjectState,
             nNewState );
 
-    return m_pIntermediateStatesSeqs[nCurInd][nDestInd];
+    return getIntermediateStatesMap()[nCurInd][nDestInd];
 }
 
 
@@ -486,7 +542,7 @@ uno::Sequence< sal_Int32 > SAL_CALL 
OCommonEmbeddedObject::getReachableStates()
         throw embed::WrongStateException( "The object has no persistence!",
                                            static_cast< ::cppu::OWeakObject* 
>(this) );
 
-    return m_aAcceptedStates;
+    return getAcceptedStates();
 }
 
 
diff --git a/embeddedobj/source/commonembedding/miscobj.cxx 
b/embeddedobj/source/commonembedding/miscobj.cxx
index d8d9a74700c1..0b15376c2535 100644
--- a/embeddedobj/source/commonembedding/miscobj.cxx
+++ b/embeddedobj/source/commonembedding/miscobj.cxx
@@ -139,42 +139,6 @@ void OCommonEmbeddedObject::CommonInit_Impl( const 
uno::Sequence< beans::NamedVa
     if ( m_aClassID.getLength() != 16 /*|| !m_aDocServiceName.getLength()*/ )
         throw uno::RuntimeException(); // something goes really wrong
 
-    // accepted states
-    m_aAcceptedStates = { /* [0] */ embed::EmbedStates::LOADED,
-                          /* [1] */ embed::EmbedStates::RUNNING,
-                          /* [2] */ embed::EmbedStates::INPLACE_ACTIVE,
-                          /* [3] */ embed::EmbedStates::UI_ACTIVE,
-                          /* [4] */ embed::EmbedStates::ACTIVE };
-    assert(m_aAcceptedStates.getLength() == NUM_SUPPORTED_STATES);
-
-
-    // intermediate states
-    // In the following table the first index points to starting state,
-    // the second one to the target state, and the sequence referenced by
-    // first two indexes contains intermediate states, that should be
-    // passed by object to reach the target state.
-    // If the sequence is empty that means that indirect switch from start
-    // state to the target state is forbidden, only if direct switch is 
possible
-    // the state can be reached.
-
-    m_pIntermediateStatesSeqs[0][2] = { embed::EmbedStates::RUNNING };
-
-    m_pIntermediateStatesSeqs[0][3] = { embed::EmbedStates::RUNNING,
-                                        embed::EmbedStates::INPLACE_ACTIVE };
-
-    m_pIntermediateStatesSeqs[0][4] = {embed::EmbedStates::RUNNING};
-
-    m_pIntermediateStatesSeqs[1][3] = { embed::EmbedStates::INPLACE_ACTIVE };
-
-    m_pIntermediateStatesSeqs[2][0] = { embed::EmbedStates::RUNNING };
-
-    m_pIntermediateStatesSeqs[3][0] = { embed::EmbedStates::INPLACE_ACTIVE,
-                                        embed::EmbedStates::RUNNING };
-
-    m_pIntermediateStatesSeqs[3][1] = { embed::EmbedStates::INPLACE_ACTIVE };
-
-    m_pIntermediateStatesSeqs[4][0] = { embed::EmbedStates::RUNNING };
-
     // verbs table
     for ( auto const & verb : std::as_const(m_aObjectVerbs) )
     {
diff --git a/embeddedobj/source/inc/commonembobj.hxx 
b/embeddedobj/source/inc/commonembobj.hxx
index 61abe0299ee1..4f641737b468 100644
--- a/embeddedobj/source/inc/commonembobj.hxx
+++ b/embeddedobj/source/inc/commonembobj.hxx
@@ -119,8 +119,6 @@ protected:
 
     css::uno::Sequence< css::embed::VerbDescriptor > m_aObjectVerbs;
 
-    css::uno::Sequence< sal_Int32 > m_aAcceptedStates;
-    css::uno::Sequence< sal_Int32 > 
m_pIntermediateStatesSeqs[NUM_SUPPORTED_STATES][NUM_SUPPORTED_STATES];
     std::map< sal_Int32, sal_Int32 > m_aVerbTable;
 
     css::uno::Reference< css::embed::XEmbeddedClient > m_xClientSite;

Reply via email to