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[] =
static EventInfoHash& getEventTransInfo()
{
static bool initialised = false;
static EventInfoHash eventTransInfo;
if ( !initialised )
static EventInfoHash eventTransInfo = [&]()
{
EventInfoHash tmp;
OUString sEventInfo;
TranslatePropMap* pTransProp = aTranslatePropMap_Impl;
int nCount = SAL_N_ELEMENTS(aTranslatePropMap_Impl);
......@@ -275,10 +274,10 @@ static EventInfoHash& getEventTransInfo()
pTransProp++;
i++;
}while(i < nCount && sEventInfo == pTransProp->sEventInfo);
eventTransInfo[sEventInfo] = infoList;
tmp[sEventInfo] = infoList;
}
initialised = true;
}
return tmp;
}();
return eventTransInfo;
}
......
......@@ -958,9 +958,7 @@ void SAL_CALL SdStyleSheet::setParentStyle( const OUString& rParentName )
Reference< XPropertySetInfo > SdStyleSheet::getPropertySetInfo()
{
throwIfDisposed();
static Reference< XPropertySetInfo > xInfo;
if( !xInfo.is() )
xInfo = GetStylePropertySet().getPropertySetInfo();
static Reference< XPropertySetInfo > xInfo = GetStylePropertySet().getPropertySetInfo();
return xInfo;
}
......
......@@ -439,17 +439,18 @@ bool BasicViewFactory::IsCacheable (const std::shared_ptr<ViewDescriptor>& rpDes
Reference<XRelocatableResource> xResource (rpDescriptor->mxView, UNO_QUERY);
if (xResource.is())
{
static ::std::vector<Reference<XResourceId> > s_aCacheableResources;
if (s_aCacheableResources.empty() )
static ::std::vector<Reference<XResourceId> > s_aCacheableResources = [&]()
{
::std::vector<Reference<XResourceId> > tmp;
std::shared_ptr<FrameworkHelper> pHelper (FrameworkHelper::Instance(*mpBase));
// 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));
s_aCacheableResources.push_back(FrameworkHelper::CreateResourceId(
tmp.push_back(FrameworkHelper::CreateResourceId(
FrameworkHelper::msSlideSorterURL, FrameworkHelper::msLeftImpressPaneURL));
}
return tmp;
}();
::std::vector<Reference<XResourceId> >::const_iterator iId;
for (iId=s_aCacheableResources.begin(); iId!=s_aCacheableResources.end(); ++iId)
......
......@@ -44,16 +44,14 @@ enum FactoryId
typedef std::unordered_map<OUString, FactoryId> FactoryMap;
namespace {
static std::shared_ptr<FactoryMap> spFactoryMap;
std::shared_ptr<FactoryMap> const & GetFactoryMap()
FactoryMap const & GetFactoryMap()
{
if (spFactoryMap == nullptr)
static FactoryMap aFactoryMap
{
spFactoryMap.reset(new FactoryMap);
(*spFactoryMap)[SdDrawingDocument_getImplementationName()] = SdDrawingDocumentFactoryId;
(*spFactoryMap)[SdPresentationDocument_getImplementationName()] = SdPresentationDocumentFactoryId;
}
return spFactoryMap;
{ SdDrawingDocument_getImplementationName(), SdDrawingDocumentFactoryId },
{ SdPresentationDocument_getImplementationName(), SdPresentationDocumentFactoryId }
};
return aFactoryMap;
};
} // end of anonymous namespace
......@@ -74,10 +72,10 @@ SAL_DLLPUBLIC_EXPORT void * sd_component_getFactory(
uno::Reference<lang::XSingleServiceFactory> xFactory;
uno::Reference<lang::XSingleComponentFactory> xComponentFactory;
const std::shared_ptr<FactoryMap>& pFactoryMap (GetFactoryMap());
const FactoryMap& rFactoryMap (GetFactoryMap());
OUString sImplementationName (OUString::createFromAscii(pImplName));
FactoryMap::const_iterator iFactory (pFactoryMap->find(sImplementationName));
if (iFactory != pFactoryMap->end())
FactoryMap::const_iterator iFactory (rFactoryMap.find(sImplementationName));
if (iFactory != rFactoryMap.end())
{
switch (iFactory->second)
{
......
......@@ -117,25 +117,24 @@ namespace {
/// Root path of the help.
OUString const & getHelpRootURL()
{
static OUString s_instURL;
if (!s_instURL.isEmpty())
return s_instURL;
s_instURL = officecfg::Office::Common::Path::Current::Help::get(comphelper::getProcessComponentContext());
if (s_instURL.isEmpty())
static OUString const s_instURL = [&]()
{
// try to determine path from default
s_instURL = "$(instpath)/" LIBO_SHARE_HELP_FOLDER;
}
// replace anything like $(instpath);
SvtPathOptions aOptions;
s_instURL = aOptions.SubstituteVariable(s_instURL);
OUString tmp = officecfg::Office::Common::Path::Current::Help::get(comphelper::getProcessComponentContext());
if (tmp.isEmpty())
{
// try to determine path from default
tmp = "$(instpath)/" LIBO_SHARE_HELP_FOLDER;
}
OUString url;
if (osl::FileBase::getFileURLFromSystemPath(s_instURL, url) == osl::FileBase::E_None)
s_instURL = url;
// replace anything like $(instpath);
SvtPathOptions aOptions;
tmp = aOptions.SubstituteVariable(tmp);
OUString url;
if (osl::FileBase::getFileURLFromSystemPath(tmp, url) == osl::FileBase::E_None)
tmp = url;
return tmp;
}();
return s_instURL;
}
......@@ -161,13 +160,8 @@ bool impl_hasHelpInstalled()
if (comphelper::LibreOfficeKit::isActive())
return false;
static OUString aLocaleStr;
if (aLocaleStr.isEmpty())
{
// detect installed locale
aLocaleStr = HelpLocaleString();
}
static OUString const aLocaleStr = HelpLocaleString();
OUString helpRootURL = getHelpRootURL() + "/" + aLocaleStr + "/err.html";
bool bOK = false;
......@@ -187,13 +181,8 @@ bool impl_hasHTMLHelpInstalled()
if (comphelper::LibreOfficeKit::isActive())
return false;
static OUString aLocaleStr;
if (aLocaleStr.isEmpty())
{
// detect installed locale
aLocaleStr = HelpLocaleString();
}
// detect installed locale
static OUString const aLocaleStr = HelpLocaleString();
OUString helpRootURL = getHelpRootURL() + "/" + aLocaleStr + "/text";
bool bOK = impl_checkHelpLocalePath( helpRootURL );
......@@ -204,7 +193,6 @@ bool impl_hasHTMLHelpInstalled()
} // namespace
/// Return the locale we prefer for displaying help
// static OUString const & HelpLocaleString()
static OUString const & HelpLocaleString()
{
if (comphelper::LibreOfficeKit::isActive())
......
......@@ -762,13 +762,12 @@ sal_Int32 SfxClassificationHelper::GetImpactLevel()
}
else if (aScale == "FIPS-199")
{
static std::map<OUString, sal_Int32> aValues;
if (aValues.empty())
static std::map<OUString, sal_Int32> const aValues
{
aValues["Low"] = 0;
aValues["Moderate"] = 1;
aValues["High"] = 2;
}
{ "Low", 0 },
{ "Moderate", 1 },
{ "High", 2 }
};
auto itValues = aValues.find(aLevel);
if (itValues == aValues.end())
return nRet;
......
......@@ -113,56 +113,40 @@ struct GroupIDToCommandGroup
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;
sal_Int16 MapGroupIDToCommandGroup( SfxGroupId nGroupID )
{
static GroupHashMap s_aHashMap;
if ( !bGroupIDMapInitialized )
static GroupHashMap s_aHashMap
{
sal_Int32 i = 0;
while ( GroupIDCommandGroupMap[i].nGroupID != SfxGroupId::NONE )
{
s_aHashMap.emplace(
GroupIDCommandGroupMap[i].nGroupID,
GroupIDCommandGroupMap[i].nCommandGroup );
++i;
}
bGroupIDMapInitialized = true;
}
{ 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 },
};
GroupHashMap::const_iterator pIter = s_aHashMap.find( nGroupID );
if ( pIter != s_aHashMap.end() )
......
......@@ -346,16 +346,8 @@ static css::uno::Reference<XInterface> JavaComponentLoader_CreateInstance(const
MutexGuard guard( getInitMutex() );
// The javaloader is never destroyed and there can be only one!
// Note that the first context wins ....
static css::uno::Reference< XInterface > xStaticRef;
if( xStaticRef.is() )
{
xRet = xStaticRef;
}
else
{
xRet = *new JavaComponentLoader(xCtx);
xStaticRef = xRet;
}
static css::uno::Reference< XInterface > xStaticRef = *new JavaComponentLoader(xCtx);
xRet = xStaticRef;
}
catch(const RuntimeException & runtimeException) {
SAL_INFO(
......
......@@ -19,6 +19,7 @@
#include <sal/config.h>
#include <array>
#include <utility>
#include <map>
......@@ -281,17 +282,16 @@ INetContentType INetContentTypes::GetContentType(OUString const & rTypeName)
//static
OUString INetContentTypes::GetContentType(INetContentType eTypeID)
{
static sal_Char const * aMap[CONTENT_TYPE_LAST + 1];
static bool bInitialized = false;
if (!bInitialized)
static std::array<sal_Char const *, CONTENT_TYPE_LAST + 1> aMap = [&]()
{
std::array<sal_Char const *, CONTENT_TYPE_LAST + 1> tmp;
for (std::size_t i = 0; i <= CONTENT_TYPE_LAST; ++i)
aMap[aStaticTypeNameMap[i].m_eTypeID] = aStaticTypeNameMap[i].m_pTypeName;
aMap[CONTENT_TYPE_UNKNOWN] = CONTENT_TYPE_STR_APP_OCTSTREAM;
aMap[CONTENT_TYPE_TEXT_PLAIN] = CONTENT_TYPE_STR_TEXT_PLAIN
"; charset=iso-8859-1";
bInitialized = true;
}
tmp[aStaticTypeNameMap[i].m_eTypeID] = aStaticTypeNameMap[i].m_pTypeName;
tmp[CONTENT_TYPE_UNKNOWN] = CONTENT_TYPE_STR_APP_OCTSTREAM;
tmp[CONTENT_TYPE_TEXT_PLAIN] = CONTENT_TYPE_STR_TEXT_PLAIN
"; charset=iso-8859-1";
return tmp;
}();
OUString aTypeName = eTypeID <= CONTENT_TYPE_LAST ? OUString::createFromAscii(aMap[eTypeID])
: OUString();
......
......@@ -94,11 +94,8 @@ SvtTabAppearanceCfg::~SvtTabAppearanceCfg( )
const Sequence<OUString>& SvtTabAppearanceCfg::GetPropertyNames()
{
static Sequence<OUString> aNames;
if(!aNames.getLength())
static Sequence<OUString> const aNames
{
static const sal_Char* aPropNames[] =
{
"Window/Drag" // 0
,"Menu/FollowMouse" // 1
,"Dialog/MousePositioning" // 2
......@@ -107,15 +104,7 @@ const Sequence<OUString>& SvtTabAppearanceCfg::GetPropertyNames()
,"FontAntiAliasing/Enabled" // 4
,"FontAntiAliasing/MinPixelHeight" // 5
#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;
}
......
......@@ -76,11 +76,8 @@ struct HtmlOptions_Impl
const Sequence<OUString>& SvxHtmlOptions::GetPropertyNames()
{
static Sequence<OUString> aNames;
if(!aNames.getLength())
static Sequence<OUString> const aNames
{
static const char* aPropNames[] =
{
"Import/UnknownTag", // 0
"Import/FontSetting", // 1
"Import/FontSize/Size_1", // 2
......@@ -97,13 +94,7 @@ const Sequence<OUString>& SvxHtmlOptions::GetPropertyNames()
"Export/Warning", // 13
"Export/Encoding", // 14
"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;
}
......
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