basic/source/basmgr/basmgr.cxx | 19 +++++++++---------- include/basic/basmgr.hxx | 4 ++-- scripting/source/basprov/basscript.cxx | 2 +- sfx2/source/appl/macroloader.cxx | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-)
New commits: commit cde416fea13c6020805ac663e254a50b2c885abd Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Wed May 11 13:17:09 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Wed May 11 21:55:11 2022 +0200 in SetGlobalUNOConstant, only retrieve old value if we need it removes some unnecessary Find() work Change-Id: I6af9c4d9a043d4361fcca1a034b2025fe7c10c28 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134200 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/basic/source/basmgr/basmgr.cxx b/basic/source/basmgr/basmgr.cxx index fec7e5eaa496..4e01bff8cc9d 100644 --- a/basic/source/basmgr/basmgr.cxx +++ b/basic/source/basmgr/basmgr.cxx @@ -1367,25 +1367,24 @@ bool BasicManager::GetGlobalUNOConstant( const OUString& rName, uno::Any& aOut ) return bRes; } -uno::Any BasicManager::SetGlobalUNOConstant( const OUString& rName, const uno::Any& _rValue ) +void BasicManager::SetGlobalUNOConstant( const OUString& rName, const uno::Any& _rValue, css::uno::Any* pOldValue ) { - uno::Any aOldValue; - StarBASIC* pStandardLib = GetStdLib(); OSL_PRECOND( pStandardLib, "BasicManager::SetGlobalUNOConstant: no lib to insert into!" ); if ( !pStandardLib ) - return aOldValue; + return; - // obtain the old value - SbxVariable* pVariable = pStandardLib->Find( rName, SbxClassType::Object ); - if ( pVariable ) - aOldValue = sbxToUnoValue( pVariable ); + if (pOldValue) + { + // obtain the old value + SbxVariable* pVariable = pStandardLib->Find( rName, SbxClassType::Object ); + if ( pVariable ) + *pOldValue = sbxToUnoValue( pVariable ); + } SbxObjectRef xUnoObj = GetSbUnoObject( _rValue.getValueType ().getTypeName () , _rValue ); xUnoObj->SetName(rName); xUnoObj->SetFlag( SbxFlagBits::DontStore ); pStandardLib->Insert( xUnoObj.get() ); - - return aOldValue; } bool BasicManager::LegacyPsswdBinaryLimitExceeded( std::vector< OUString >& _out_rModuleNames ) diff --git a/include/basic/basmgr.hxx b/include/basic/basmgr.hxx index 11c90fea1dfa..94fea1a0bf77 100644 --- a/include/basic/basmgr.hxx +++ b/include/basic/basmgr.hxx @@ -174,10 +174,10 @@ public: /** sets a global constant in the basic library, referring to some UNO object, to a new value. If a constant with this name already existed before, its value is changed, and the old constant is - returned. If it does not yet exist, it is newly created, and inserted into the basic library. + returned in pOldValue. If it does not yet exist, it is newly created, and inserted into the basic library. */ IF_MERGELIBS(BASIC_DLLPUBLIC) - css::uno::Any SetGlobalUNOConstant( const OUString& rName, const css::uno::Any& _rValue ); + void SetGlobalUNOConstant( const OUString& rName, const css::uno::Any& _rValue, css::uno::Any* pOldValue = nullptr ); /** retrieves a global constant in the basic library, referring to some UNO object, returns true if a value is found ( value is in aOut ) false otherwise. */ IF_MERGELIBS(BASIC_DLLPUBLIC) diff --git a/scripting/source/basprov/basscript.cxx b/scripting/source/basprov/basscript.cxx index d64fa5af4357..b5a3f6136534 100644 --- a/scripting/source/basprov/basscript.cxx +++ b/scripting/source/basprov/basscript.cxx @@ -242,7 +242,7 @@ constexpr OUStringLiteral BASSCRIPT_PROPERTY_CALLER = u"Caller"; // if it's a document-based script, temporarily reset ThisComponent to the script invocation context Any aOldThisComponent; if ( m_documentBasicManager && m_xDocumentScriptContext.is() ) - aOldThisComponent = m_documentBasicManager->SetGlobalUNOConstant( "ThisComponent", Any( m_xDocumentScriptContext ) ); + m_documentBasicManager->SetGlobalUNOConstant( "ThisComponent", Any( m_xDocumentScriptContext ), &aOldThisComponent ); if ( m_caller.hasElements() && m_caller[ 0 ].hasValue() ) { diff --git a/sfx2/source/appl/macroloader.cxx b/sfx2/source/appl/macroloader.cxx index fff7fc140450..0892bb78e4d9 100644 --- a/sfx2/source/appl/macroloader.cxx +++ b/sfx2/source/appl/macroloader.cxx @@ -275,7 +275,7 @@ ErrCode SfxMacroLoader::loadMacro( const OUString& rURL, css::uno::Any& rRetval, if ( bSetGlobalThisComponent ) { // document is executed via AppBASIC, adjust ThisComponent variable - aOldThisComponent = pAppMgr->SetGlobalUNOConstant( "ThisComponent", Any( pDoc->GetModel() ) ); + pAppMgr->SetGlobalUNOConstant( "ThisComponent", Any( pDoc->GetModel() ), &aOldThisComponent ); } // just to let the shell be alive