include/comphelper/IdPropArrayHelper.hxx | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-)
New commits: commit 98a2cef1ee9c76897af64ff0a1e1efd280796f36 Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Thu Nov 11 19:08:17 2021 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sat Nov 13 06:26:52 2021 +0100 modernise IdPropArrayHelper a little Change-Id: I73bbb59d41ba752e5bbb798ae590e60fdb550d8b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125115 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/include/comphelper/IdPropArrayHelper.hxx b/include/comphelper/IdPropArrayHelper.hxx index 34e403b3ab0a..c702acb98065 100644 --- a/include/comphelper/IdPropArrayHelper.hxx +++ b/include/comphelper/IdPropArrayHelper.hxx @@ -16,40 +16,32 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_COMPHELPER_IDPROPARRAYHELPER_HXX -#define INCLUDED_COMPHELPER_IDPROPARRAYHELPER_HXX +#pragma once #include <sal/config.h> -#include <map> - #include <osl/mutex.hxx> -#include <osl/diagnose.h> #include <rtl/instance.hxx> #include <cppuhelper/propshlp.hxx> +#include <cassert> +#include <unordered_map> namespace comphelper { - // OIdPropertyArrayUsageHelper - template <typename TYPE> struct OIdPropertyArrayUsageHelperMutex : public rtl::Static< ::osl::Mutex, OIdPropertyArrayUsageHelperMutex<TYPE> > {}; - typedef std::map< sal_Int32, ::cppu::IPropertyArrayHelper* > OIdPropertyArrayMap; + typedef std::unordered_map< sal_Int32, ::cppu::IPropertyArrayHelper* > OIdPropertyArrayMap; template <class TYPE> class OIdPropertyArrayUsageHelper { - protected: - static sal_Int32 s_nRefCount; - static OIdPropertyArrayMap* s_pMap; - public: OIdPropertyArrayUsageHelper(); virtual ~OIdPropertyArrayUsageHelper() { ::osl::MutexGuard aGuard(OIdPropertyArrayUsageHelperMutex<TYPE>::get()); - OSL_ENSURE(s_nRefCount > 0, "OIdPropertyArrayUsageHelper::~OIdPropertyArrayUsageHelper : suspicious call : have a refcount of 0 !"); + assert(s_nRefCount > 0 && "OIdPropertyArrayUsageHelper::~OIdPropertyArrayUsageHelper : suspicious call : have a refcount of 0 !"); if (!--s_nRefCount) { // delete the element @@ -73,42 +65,41 @@ namespace comphelper @return a pointer to the newly created array helper. Must not be NULL. */ virtual ::cppu::IPropertyArrayHelper* createArrayHelper(sal_Int32 nId) const = 0; + private: + static sal_Int32 s_nRefCount; + static OIdPropertyArrayMap* s_pMap; }; - template<class TYPE> sal_Int32 OIdPropertyArrayUsageHelper< TYPE >::s_nRefCount = 0; template<class TYPE> OIdPropertyArrayMap* OIdPropertyArrayUsageHelper< TYPE >::s_pMap = nullptr; - template <class TYPE> OIdPropertyArrayUsageHelper<TYPE>::OIdPropertyArrayUsageHelper() { ::osl::MutexGuard aGuard(OIdPropertyArrayUsageHelperMutex<TYPE>::get()); // create the map if necessary - if (s_pMap == nullptr) + if (!s_pMap) s_pMap = new OIdPropertyArrayMap; ++s_nRefCount; } - template <class TYPE> ::cppu::IPropertyArrayHelper* OIdPropertyArrayUsageHelper<TYPE>::getArrayHelper(sal_Int32 nId) { - OSL_ENSURE(s_nRefCount, "OIdPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !"); + assert(s_nRefCount && "OIdPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !"); ::osl::MutexGuard aGuard(OIdPropertyArrayUsageHelperMutex<TYPE>::get()); // do we have the array already? auto& rEntry = (*s_pMap)[nId]; if (!rEntry) { rEntry = createArrayHelper(nId); - OSL_ENSURE((*s_pMap)[nId], "OIdPropertyArrayUsageHelper::getArrayHelper : createArrayHelper returned nonsense !"); + assert(rEntry && "OIdPropertyArrayUsageHelper::getArrayHelper : createArrayHelper returned nonsense !"); } return (*s_pMap)[nId]; } } -#endif // INCLUDED_COMPHELPER_IDPROPARRAYHELPER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */