Kaydet (Commit) 06ad764c authored tarafından Noel Grandin's avatar Noel Grandin

improve function-local statics in scripting..svtools

Change-Id: Idf3785a1fbc6fc5b8efbdc4cd363047709f3af91
Reviewed-on: https://gerrit.libreoffice.org/63782
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst a73494cf
...@@ -256,10 +256,9 @@ static TranslatePropMap aTranslatePropMap_Impl[] = ...@@ -256,10 +256,9 @@ static TranslatePropMap aTranslatePropMap_Impl[] =
static EventInfoHash& getEventTransInfo() static EventInfoHash& getEventTransInfo()
{ {
static bool initialised = false; static EventInfoHash eventTransInfo = [&]()
static EventInfoHash eventTransInfo;
if ( !initialised )
{ {
EventInfoHash tmp;
OUString sEventInfo; OUString sEventInfo;
TranslatePropMap* pTransProp = aTranslatePropMap_Impl; TranslatePropMap* pTransProp = aTranslatePropMap_Impl;
int nCount = SAL_N_ELEMENTS(aTranslatePropMap_Impl); int nCount = SAL_N_ELEMENTS(aTranslatePropMap_Impl);
...@@ -275,10 +274,10 @@ static EventInfoHash& getEventTransInfo() ...@@ -275,10 +274,10 @@ static EventInfoHash& getEventTransInfo()
pTransProp++; pTransProp++;
i++; i++;
}while(i < nCount && sEventInfo == pTransProp->sEventInfo); }while(i < nCount && sEventInfo == pTransProp->sEventInfo);
eventTransInfo[sEventInfo] = infoList; tmp[sEventInfo] = infoList;
} }
initialised = true; return tmp;
} }();
return eventTransInfo; return eventTransInfo;
} }
......
...@@ -958,9 +958,7 @@ void SAL_CALL SdStyleSheet::setParentStyle( const OUString& rParentName ) ...@@ -958,9 +958,7 @@ void SAL_CALL SdStyleSheet::setParentStyle( const OUString& rParentName )
Reference< XPropertySetInfo > SdStyleSheet::getPropertySetInfo() Reference< XPropertySetInfo > SdStyleSheet::getPropertySetInfo()
{ {
throwIfDisposed(); throwIfDisposed();
static Reference< XPropertySetInfo > xInfo; static Reference< XPropertySetInfo > xInfo = GetStylePropertySet().getPropertySetInfo();
if( !xInfo.is() )
xInfo = GetStylePropertySet().getPropertySetInfo();
return xInfo; return xInfo;
} }
......
...@@ -439,17 +439,18 @@ bool BasicViewFactory::IsCacheable (const std::shared_ptr<ViewDescriptor>& rpDes ...@@ -439,17 +439,18 @@ bool BasicViewFactory::IsCacheable (const std::shared_ptr<ViewDescriptor>& rpDes
Reference<XRelocatableResource> xResource (rpDescriptor->mxView, UNO_QUERY); Reference<XRelocatableResource> xResource (rpDescriptor->mxView, UNO_QUERY);
if (xResource.is()) if (xResource.is())
{ {
static ::std::vector<Reference<XResourceId> > s_aCacheableResources; static ::std::vector<Reference<XResourceId> > s_aCacheableResources = [&]()
if (s_aCacheableResources.empty() )
{ {
::std::vector<Reference<XResourceId> > tmp;
std::shared_ptr<FrameworkHelper> pHelper (FrameworkHelper::Instance(*mpBase)); std::shared_ptr<FrameworkHelper> pHelper (FrameworkHelper::Instance(*mpBase));
// The slide sorter and the task panel are cacheable and relocatable. // The slide sorter and the task panel are cacheable and relocatable.
s_aCacheableResources.push_back(FrameworkHelper::CreateResourceId( tmp.push_back(FrameworkHelper::CreateResourceId(
FrameworkHelper::msSlideSorterURL, FrameworkHelper::msLeftDrawPaneURL)); FrameworkHelper::msSlideSorterURL, FrameworkHelper::msLeftDrawPaneURL));
s_aCacheableResources.push_back(FrameworkHelper::CreateResourceId( tmp.push_back(FrameworkHelper::CreateResourceId(
FrameworkHelper::msSlideSorterURL, FrameworkHelper::msLeftImpressPaneURL)); FrameworkHelper::msSlideSorterURL, FrameworkHelper::msLeftImpressPaneURL));
} return tmp;
}();
::std::vector<Reference<XResourceId> >::const_iterator iId; ::std::vector<Reference<XResourceId> >::const_iterator iId;
for (iId=s_aCacheableResources.begin(); iId!=s_aCacheableResources.end(); ++iId) for (iId=s_aCacheableResources.begin(); iId!=s_aCacheableResources.end(); ++iId)
......
...@@ -44,16 +44,14 @@ enum FactoryId ...@@ -44,16 +44,14 @@ enum FactoryId
typedef std::unordered_map<OUString, FactoryId> FactoryMap; typedef std::unordered_map<OUString, FactoryId> FactoryMap;
namespace { namespace {
static std::shared_ptr<FactoryMap> spFactoryMap; FactoryMap const & GetFactoryMap()
std::shared_ptr<FactoryMap> const & GetFactoryMap()
{ {
if (spFactoryMap == nullptr) static FactoryMap aFactoryMap
{ {
spFactoryMap.reset(new FactoryMap); { SdDrawingDocument_getImplementationName(), SdDrawingDocumentFactoryId },
(*spFactoryMap)[SdDrawingDocument_getImplementationName()] = SdDrawingDocumentFactoryId; { SdPresentationDocument_getImplementationName(), SdPresentationDocumentFactoryId }
(*spFactoryMap)[SdPresentationDocument_getImplementationName()] = SdPresentationDocumentFactoryId; };
} return aFactoryMap;
return spFactoryMap;
}; };
} // end of anonymous namespace } // end of anonymous namespace
...@@ -74,10 +72,10 @@ SAL_DLLPUBLIC_EXPORT void * sd_component_getFactory( ...@@ -74,10 +72,10 @@ SAL_DLLPUBLIC_EXPORT void * sd_component_getFactory(
uno::Reference<lang::XSingleServiceFactory> xFactory; uno::Reference<lang::XSingleServiceFactory> xFactory;
uno::Reference<lang::XSingleComponentFactory> xComponentFactory; uno::Reference<lang::XSingleComponentFactory> xComponentFactory;
const std::shared_ptr<FactoryMap>& pFactoryMap (GetFactoryMap()); const FactoryMap& rFactoryMap (GetFactoryMap());
OUString sImplementationName (OUString::createFromAscii(pImplName)); OUString sImplementationName (OUString::createFromAscii(pImplName));
FactoryMap::const_iterator iFactory (pFactoryMap->find(sImplementationName)); FactoryMap::const_iterator iFactory (rFactoryMap.find(sImplementationName));
if (iFactory != pFactoryMap->end()) if (iFactory != rFactoryMap.end())
{ {
switch (iFactory->second) switch (iFactory->second)
{ {
......
...@@ -117,25 +117,24 @@ namespace { ...@@ -117,25 +117,24 @@ namespace {
/// Root path of the help. /// Root path of the help.
OUString const & getHelpRootURL() OUString const & getHelpRootURL()
{ {
static OUString s_instURL; static OUString const s_instURL = [&]()
if (!s_instURL.isEmpty())
return s_instURL;
s_instURL = officecfg::Office::Common::Path::Current::Help::get(comphelper::getProcessComponentContext());
if (s_instURL.isEmpty())
{ {
// try to determine path from default OUString tmp = officecfg::Office::Common::Path::Current::Help::get(comphelper::getProcessComponentContext());
s_instURL = "$(instpath)/" LIBO_SHARE_HELP_FOLDER; if (tmp.isEmpty())
} {
// try to determine path from default
// replace anything like $(instpath); tmp = "$(instpath)/" LIBO_SHARE_HELP_FOLDER;
SvtPathOptions aOptions; }
s_instURL = aOptions.SubstituteVariable(s_instURL);
OUString url; // replace anything like $(instpath);
if (osl::FileBase::getFileURLFromSystemPath(s_instURL, url) == osl::FileBase::E_None) SvtPathOptions aOptions;
s_instURL = url; tmp = aOptions.SubstituteVariable(tmp);
OUString url;
if (osl::FileBase::getFileURLFromSystemPath(tmp, url) == osl::FileBase::E_None)
tmp = url;
return tmp;
}();
return s_instURL; return s_instURL;
} }
...@@ -161,13 +160,8 @@ bool impl_hasHelpInstalled() ...@@ -161,13 +160,8 @@ bool impl_hasHelpInstalled()
if (comphelper::LibreOfficeKit::isActive()) if (comphelper::LibreOfficeKit::isActive())
return false; return false;
static OUString aLocaleStr;
if (aLocaleStr.isEmpty())
{
// detect installed locale // detect installed locale
aLocaleStr = HelpLocaleString(); static OUString const aLocaleStr = HelpLocaleString();
}
OUString helpRootURL = getHelpRootURL() + "/" + aLocaleStr + "/err.html"; OUString helpRootURL = getHelpRootURL() + "/" + aLocaleStr + "/err.html";
bool bOK = false; bool bOK = false;
...@@ -187,13 +181,8 @@ bool impl_hasHTMLHelpInstalled() ...@@ -187,13 +181,8 @@ bool impl_hasHTMLHelpInstalled()
if (comphelper::LibreOfficeKit::isActive()) if (comphelper::LibreOfficeKit::isActive())
return false; return false;
static OUString aLocaleStr; // detect installed locale
static OUString const aLocaleStr = HelpLocaleString();
if (aLocaleStr.isEmpty())
{
// detect installed locale
aLocaleStr = HelpLocaleString();
}
OUString helpRootURL = getHelpRootURL() + "/" + aLocaleStr + "/text"; OUString helpRootURL = getHelpRootURL() + "/" + aLocaleStr + "/text";
bool bOK = impl_checkHelpLocalePath( helpRootURL ); bool bOK = impl_checkHelpLocalePath( helpRootURL );
...@@ -204,7 +193,6 @@ bool impl_hasHTMLHelpInstalled() ...@@ -204,7 +193,6 @@ bool impl_hasHTMLHelpInstalled()
} // namespace } // namespace
/// Return the locale we prefer for displaying help /// Return the locale we prefer for displaying help
// static OUString const & HelpLocaleString()
static OUString const & HelpLocaleString() static OUString const & HelpLocaleString()
{ {
if (comphelper::LibreOfficeKit::isActive()) if (comphelper::LibreOfficeKit::isActive())
......
...@@ -762,13 +762,12 @@ sal_Int32 SfxClassificationHelper::GetImpactLevel() ...@@ -762,13 +762,12 @@ sal_Int32 SfxClassificationHelper::GetImpactLevel()
} }
else if (aScale == "FIPS-199") else if (aScale == "FIPS-199")
{ {
static std::map<OUString, sal_Int32> aValues; static std::map<OUString, sal_Int32> const aValues
if (aValues.empty())
{ {
aValues["Low"] = 0; { "Low", 0 },
aValues["Moderate"] = 1; { "Moderate", 1 },
aValues["High"] = 2; { "High", 2 }
} };
auto itValues = aValues.find(aLevel); auto itValues = aValues.find(aLevel);
if (itValues == aValues.end()) if (itValues == aValues.end())
return nRet; return nRet;
......
...@@ -113,56 +113,40 @@ struct GroupIDToCommandGroup ...@@ -113,56 +113,40 @@ struct GroupIDToCommandGroup
sal_Int16 const nCommandGroup; sal_Int16 const nCommandGroup;
}; };
static bool bGroupIDMapInitialized = false;
static const GroupIDToCommandGroup GroupIDCommandGroupMap[] =
{
{ SfxGroupId::Intern , frame::CommandGroup::INTERNAL },
{ SfxGroupId::Application , frame::CommandGroup::APPLICATION },
{ SfxGroupId::Document , frame::CommandGroup::DOCUMENT },
{ SfxGroupId::View , frame::CommandGroup::VIEW },
{ SfxGroupId::Edit , frame::CommandGroup::EDIT },
{ SfxGroupId::Macro , frame::CommandGroup::MACRO },
{ SfxGroupId::Options , frame::CommandGroup::OPTIONS },
{ SfxGroupId::Math , frame::CommandGroup::MATH },
{ SfxGroupId::Navigator , frame::CommandGroup::NAVIGATOR },
{ SfxGroupId::Insert , frame::CommandGroup::INSERT },
{ SfxGroupId::Format , frame::CommandGroup::FORMAT },
{ SfxGroupId::Template , frame::CommandGroup::TEMPLATE },
{ SfxGroupId::Text , frame::CommandGroup::TEXT },
{ SfxGroupId::Frame , frame::CommandGroup::FRAME },
{ SfxGroupId::Graphic , frame::CommandGroup::GRAPHIC },
{ SfxGroupId::Table , frame::CommandGroup::TABLE },
{ SfxGroupId::Enumeration , frame::CommandGroup::ENUMERATION },
{ SfxGroupId::Data , frame::CommandGroup::DATA },
{ SfxGroupId::Special , frame::CommandGroup::SPECIAL },
{ SfxGroupId::Image , frame::CommandGroup::IMAGE },
{ SfxGroupId::Chart , frame::CommandGroup::CHART },
{ SfxGroupId::Explorer , frame::CommandGroup::EXPLORER },
{ SfxGroupId::Connector , frame::CommandGroup::CONNECTOR },
{ SfxGroupId::Modify , frame::CommandGroup::MODIFY },
{ SfxGroupId::Drawing , frame::CommandGroup::DRAWING },
{ SfxGroupId::Controls , frame::CommandGroup::CONTROLS },
{ SfxGroupId::NONE, 0 }
};
typedef std::unordered_map< SfxGroupId, sal_Int16 > GroupHashMap; typedef std::unordered_map< SfxGroupId, sal_Int16 > GroupHashMap;
sal_Int16 MapGroupIDToCommandGroup( SfxGroupId nGroupID ) sal_Int16 MapGroupIDToCommandGroup( SfxGroupId nGroupID )
{ {
static GroupHashMap s_aHashMap; static GroupHashMap s_aHashMap
if ( !bGroupIDMapInitialized )
{ {
sal_Int32 i = 0; { SfxGroupId::Intern , frame::CommandGroup::INTERNAL },
while ( GroupIDCommandGroupMap[i].nGroupID != SfxGroupId::NONE ) { SfxGroupId::Application , frame::CommandGroup::APPLICATION },
{ { SfxGroupId::Document , frame::CommandGroup::DOCUMENT },
s_aHashMap.emplace( { SfxGroupId::View , frame::CommandGroup::VIEW },
GroupIDCommandGroupMap[i].nGroupID, { SfxGroupId::Edit , frame::CommandGroup::EDIT },
GroupIDCommandGroupMap[i].nCommandGroup ); { SfxGroupId::Macro , frame::CommandGroup::MACRO },
++i; { SfxGroupId::Options , frame::CommandGroup::OPTIONS },
} { SfxGroupId::Math , frame::CommandGroup::MATH },
bGroupIDMapInitialized = true; { SfxGroupId::Navigator , frame::CommandGroup::NAVIGATOR },
} { SfxGroupId::Insert , frame::CommandGroup::INSERT },
{ SfxGroupId::Format , frame::CommandGroup::FORMAT },
{ SfxGroupId::Template , frame::CommandGroup::TEMPLATE },
{ SfxGroupId::Text , frame::CommandGroup::TEXT },
{ SfxGroupId::Frame , frame::CommandGroup::FRAME },
{ SfxGroupId::Graphic , frame::CommandGroup::GRAPHIC },
{ SfxGroupId::Table , frame::CommandGroup::TABLE },
{ SfxGroupId::Enumeration , frame::CommandGroup::ENUMERATION },
{ SfxGroupId::Data , frame::CommandGroup::DATA },
{ SfxGroupId::Special , frame::CommandGroup::SPECIAL },
{ SfxGroupId::Image , frame::CommandGroup::IMAGE },
{ SfxGroupId::Chart , frame::CommandGroup::CHART },
{ SfxGroupId::Explorer , frame::CommandGroup::EXPLORER },
{ SfxGroupId::Connector , frame::CommandGroup::CONNECTOR },
{ SfxGroupId::Modify , frame::CommandGroup::MODIFY },
{ SfxGroupId::Drawing , frame::CommandGroup::DRAWING },
{ SfxGroupId::Controls , frame::CommandGroup::CONTROLS },
};
GroupHashMap::const_iterator pIter = s_aHashMap.find( nGroupID ); GroupHashMap::const_iterator pIter = s_aHashMap.find( nGroupID );
if ( pIter != s_aHashMap.end() ) if ( pIter != s_aHashMap.end() )
......
...@@ -346,16 +346,8 @@ static css::uno::Reference<XInterface> JavaComponentLoader_CreateInstance(const ...@@ -346,16 +346,8 @@ static css::uno::Reference<XInterface> JavaComponentLoader_CreateInstance(const
MutexGuard guard( getInitMutex() ); MutexGuard guard( getInitMutex() );
// The javaloader is never destroyed and there can be only one! // The javaloader is never destroyed and there can be only one!
// Note that the first context wins .... // Note that the first context wins ....
static css::uno::Reference< XInterface > xStaticRef; static css::uno::Reference< XInterface > xStaticRef = *new JavaComponentLoader(xCtx);
if( xStaticRef.is() ) xRet = xStaticRef;
{
xRet = xStaticRef;
}
else
{
xRet = *new JavaComponentLoader(xCtx);
xStaticRef = xRet;
}
} }
catch(const RuntimeException & runtimeException) { catch(const RuntimeException & runtimeException) {
SAL_INFO( SAL_INFO(
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <sal/config.h> #include <sal/config.h>
#include <array>
#include <utility> #include <utility>
#include <map> #include <map>
...@@ -281,17 +282,16 @@ INetContentType INetContentTypes::GetContentType(OUString const & rTypeName) ...@@ -281,17 +282,16 @@ INetContentType INetContentTypes::GetContentType(OUString const & rTypeName)
//static //static
OUString INetContentTypes::GetContentType(INetContentType eTypeID) OUString INetContentTypes::GetContentType(INetContentType eTypeID)
{ {
static sal_Char const * aMap[CONTENT_TYPE_LAST + 1]; static std::array<sal_Char const *, CONTENT_TYPE_LAST + 1> aMap = [&]()
static bool bInitialized = false;
if (!bInitialized)
{ {
std::array<sal_Char const *, CONTENT_TYPE_LAST + 1> tmp;
for (std::size_t i = 0; i <= CONTENT_TYPE_LAST; ++i) for (std::size_t i = 0; i <= CONTENT_TYPE_LAST; ++i)
aMap[aStaticTypeNameMap[i].m_eTypeID] = aStaticTypeNameMap[i].m_pTypeName; tmp[aStaticTypeNameMap[i].m_eTypeID] = aStaticTypeNameMap[i].m_pTypeName;
aMap[CONTENT_TYPE_UNKNOWN] = CONTENT_TYPE_STR_APP_OCTSTREAM; tmp[CONTENT_TYPE_UNKNOWN] = CONTENT_TYPE_STR_APP_OCTSTREAM;
aMap[CONTENT_TYPE_TEXT_PLAIN] = CONTENT_TYPE_STR_TEXT_PLAIN tmp[CONTENT_TYPE_TEXT_PLAIN] = CONTENT_TYPE_STR_TEXT_PLAIN
"; charset=iso-8859-1"; "; charset=iso-8859-1";
bInitialized = true; return tmp;
} }();
OUString aTypeName = eTypeID <= CONTENT_TYPE_LAST ? OUString::createFromAscii(aMap[eTypeID]) OUString aTypeName = eTypeID <= CONTENT_TYPE_LAST ? OUString::createFromAscii(aMap[eTypeID])
: OUString(); : OUString();
......
...@@ -94,11 +94,8 @@ SvtTabAppearanceCfg::~SvtTabAppearanceCfg( ) ...@@ -94,11 +94,8 @@ SvtTabAppearanceCfg::~SvtTabAppearanceCfg( )
const Sequence<OUString>& SvtTabAppearanceCfg::GetPropertyNames() const Sequence<OUString>& SvtTabAppearanceCfg::GetPropertyNames()
{ {
static Sequence<OUString> aNames; static Sequence<OUString> const aNames
if(!aNames.getLength())
{ {
static const sal_Char* aPropNames[] =
{
"Window/Drag" // 0 "Window/Drag" // 0
,"Menu/FollowMouse" // 1 ,"Menu/FollowMouse" // 1
,"Dialog/MousePositioning" // 2 ,"Dialog/MousePositioning" // 2
...@@ -107,15 +104,7 @@ const Sequence<OUString>& SvtTabAppearanceCfg::GetPropertyNames() ...@@ -107,15 +104,7 @@ const Sequence<OUString>& SvtTabAppearanceCfg::GetPropertyNames()
,"FontAntiAliasing/Enabled" // 4 ,"FontAntiAliasing/Enabled" // 4
,"FontAntiAliasing/MinPixelHeight" // 5 ,"FontAntiAliasing/MinPixelHeight" // 5
#endif #endif
}; };
const int nCount = SAL_N_ELEMENTS( aPropNames );
aNames.realloc(nCount);
const sal_Char** pAsciiNames = aPropNames;
OUString* pNames = aNames.getArray();
for(int i = 0; i < nCount; ++i, ++pNames, ++pAsciiNames)
*pNames = OUString::createFromAscii( *pAsciiNames );
}
return aNames; return aNames;
} }
......
...@@ -76,11 +76,8 @@ struct HtmlOptions_Impl ...@@ -76,11 +76,8 @@ struct HtmlOptions_Impl
const Sequence<OUString>& SvxHtmlOptions::GetPropertyNames() const Sequence<OUString>& SvxHtmlOptions::GetPropertyNames()
{ {
static Sequence<OUString> aNames; static Sequence<OUString> const aNames
if(!aNames.getLength())
{ {
static const char* aPropNames[] =
{
"Import/UnknownTag", // 0 "Import/UnknownTag", // 0
"Import/FontSetting", // 1 "Import/FontSetting", // 1
"Import/FontSize/Size_1", // 2 "Import/FontSize/Size_1", // 2
...@@ -97,13 +94,7 @@ const Sequence<OUString>& SvxHtmlOptions::GetPropertyNames() ...@@ -97,13 +94,7 @@ const Sequence<OUString>& SvxHtmlOptions::GetPropertyNames()
"Export/Warning", // 13 "Export/Warning", // 13
"Export/Encoding", // 14 "Export/Encoding", // 14
"Import/NumbersEnglishUS" // 15 "Import/NumbersEnglishUS" // 15
}; };
const int nCount = SAL_N_ELEMENTS(aPropNames);
aNames.realloc(nCount);
OUString* pNames = aNames.getArray();
for(int i = 0; i < nCount; i++)
pNames[i] = OUString::createFromAscii(aPropNames[i]);
}
return aNames; return aNames;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment