summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2021-11-15 21:51:18 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-11-16 11:54:10 +0100
commit2d2dc141f6d0eaa1e4737450fac707c67c05387c (patch)
tree22e33c84d3739aac669bf1762e9d49459d7fafdb /oox
parent0659c488efb00e2a87fa98edf498288470688a9a (diff)
rtl::Static->thread-safe static in oox
Change-Id: I4436188aa52766a07dadc1accb52c524666ae2f4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125258 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'oox')
-rw-r--r--oox/source/core/filterbase.cxx11
-rw-r--r--oox/source/core/xmlfilterbase.cxx16
2 files changed, 13 insertions, 14 deletions
diff --git a/oox/source/core/filterbase.cxx b/oox/source/core/filterbase.cxx
index 95545374e8a4..6ae55238c3eb 100644
--- a/oox/source/core/filterbase.cxx
+++ b/oox/source/core/filterbase.cxx
@@ -33,7 +33,6 @@
#include <comphelper/scopeguard.hxx>
#include <unotools/mediadescriptor.hxx>
#include <osl/diagnose.h>
-#include <rtl/instance.hxx>
#include <rtl/uri.hxx>
#include <memory>
#include <mutex>
@@ -72,7 +71,11 @@ struct UrlPool
::std::set< OUString > maUrls;
};
-struct StaticUrlPool : public ::rtl::Static< UrlPool, StaticUrlPool > {};
+UrlPool& StaticUrlPool()
+{
+ static UrlPool SINGLETON;
+ return SINGLETON;
+}
/** This guard prevents recursive loading/saving of the same document. */
class DocumentOpenedGuard
@@ -92,7 +95,7 @@ private:
DocumentOpenedGuard::DocumentOpenedGuard( const OUString& rUrl )
{
- UrlPool& rUrlPool = StaticUrlPool::get();
+ UrlPool& rUrlPool = StaticUrlPool();
std::scoped_lock aGuard( rUrlPool.maMutex );
mbValid = rUrl.isEmpty() || (rUrlPool.maUrls.count( rUrl ) == 0);
if( mbValid && !rUrl.isEmpty() )
@@ -104,7 +107,7 @@ DocumentOpenedGuard::DocumentOpenedGuard( const OUString& rUrl )
DocumentOpenedGuard::~DocumentOpenedGuard()
{
- UrlPool& rUrlPool = StaticUrlPool::get();
+ UrlPool& rUrlPool = StaticUrlPool();
std::scoped_lock aGuard( rUrlPool.maMutex );
if( !maUrl.isEmpty() )
rUrlPool.maUrls.erase( maUrl );
diff --git a/oox/source/core/xmlfilterbase.cxx b/oox/source/core/xmlfilterbase.cxx
index 7a9728e88f32..daea0ad49962 100644
--- a/oox/source/core/xmlfilterbase.cxx
+++ b/oox/source/core/xmlfilterbase.cxx
@@ -36,7 +36,6 @@
#include <sax/fshelper.hxx>
#include <rtl/strbuf.hxx>
#include <rtl/ustrbuf.hxx>
-#include <rtl/instance.hxx>
#include <osl/diagnose.h>
#include <sal/log.hxx>
#include <i18nlangtag/languagetag.hxx>
@@ -92,13 +91,10 @@ using ::sax_fastparser::FastSerializerHelper;
namespace {
-struct NamespaceIds: public rtl::StaticWithInit<
- Sequence< beans::Pair< OUString, sal_Int32 > >,
- NamespaceIds>
+const Sequence< beans::Pair< OUString, sal_Int32 > >& NamespaceIds()
{
- Sequence< beans::Pair< OUString, sal_Int32 > > operator()()
- {
- return css::uno::Sequence<css::beans::Pair<OUString, sal_Int32>>{
+ static const Sequence< beans::Pair< OUString, sal_Int32 > > SINGLETON
+ {
{"http://www.w3.org/XML/1998/namespace", NMSP_xml},
{"http://schemas.openxmlformats.org/package/2006/relationships",
NMSP_packageRel},
@@ -151,12 +147,12 @@ struct NamespaceIds: public rtl::StaticWithInit<
{"http://schemas.microsoft.com/office/drawing/2012/chart",
NMSP_c15},
};
- }
+ return SINGLETON;
};
void registerNamespaces( FastParser& rParser )
{
- const Sequence< beans::Pair<OUString, sal_Int32> >& ids = NamespaceIds::get();
+ const Sequence< beans::Pair<OUString, sal_Int32> >& ids = NamespaceIds();
// Filter out duplicates: a namespace can have multiple URLs, think of
// strict vs transitional.
@@ -467,7 +463,7 @@ bool XmlFilterBase::importFragment( const ::rtl::Reference< FragmentHandler >& r
rxSerializer->fastSerialize( rxHandler,
mxImpl->maFastParser.getTokenHandler(),
Sequence< StringPair >(),
- NamespaceIds::get() );
+ NamespaceIds() );
return true;
}
catch( Exception& )