oox/source/core/filterbase.cxx | 11 +++++++---- oox/source/core/xmlfilterbase.cxx | 16 ++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-)
New commits: commit 2d2dc141f6d0eaa1e4737450fac707c67c05387c Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Mon Nov 15 21:51:18 2021 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Tue Nov 16 11:54:10 2021 +0100 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.gran...@collabora.co.uk> 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& )