summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2021-06-20 19:10:50 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-06-21 08:47:52 +0200
commit2e3046cc6fdebb52cfb1cdc114a9c2cd26bcc178 (patch)
tree582a558172b53834f52b394313609915140651b5 /sal
parent16231fc68973ec36c7f1e4ba5e6bef7059f9ee25 (diff)
simplify bootstrap_map (tdf#135316 related)
No need for this indirection Change-Id: I87c90c9f1a7904f5a506acac631fe5a1f52f9190 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117521 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sal')
-rw-r--r--sal/rtl/bootstrap.cxx59
1 files changed, 13 insertions, 46 deletions
diff --git a/sal/rtl/bootstrap.cxx b/sal/rtl/bootstrap.cxx
index 4f5c2f732dc1..45c330a56edb 100644
--- a/sal/rtl/bootstrap.cxx
+++ b/sal/rtl/bootstrap.cxx
@@ -581,38 +581,10 @@ void Bootstrap_Impl::expandValue(
namespace {
-struct bootstrap_map {
- typedef std::unordered_map<
- OUString, Bootstrap_Impl * > t;
-
- bootstrap_map(const bootstrap_map&) = delete;
- bootstrap_map& operator=(const bootstrap_map&) = delete;
-
- // get and release must only be called properly synchronized via some mutex
- // (e.g., osl::Mutex::getGlobalMutex()):
-
- static t * get()
- {
- if (!m_map)
- m_map = new t;
-
- return m_map;
- }
-
- static void release()
- {
- if (m_map != nullptr && m_map->empty())
- {
- delete m_map;
- m_map = nullptr;
- }
- }
-
-private:
- static t * m_map;
-};
-
-bootstrap_map::t * bootstrap_map::m_map = nullptr;
+// This map must only be called properly synchronized via some mutex
+// (e.g., osl::Mutex::getGlobalMutex()):
+typedef std::unordered_map< OUString, Bootstrap_Impl * > bootstrap_map_t;
+bootstrap_map_t bootstrap_map;
}
@@ -633,21 +605,18 @@ rtlBootstrapHandle SAL_CALL rtl_bootstrap_args_open(rtl_uString * pIniName)
Bootstrap_Impl * that;
osl::ResettableMutexGuard guard(osl::Mutex::getGlobalMutex());
- bootstrap_map::t* p_bootstrap_map = bootstrap_map::get();
- bootstrap_map::t::const_iterator iFind(p_bootstrap_map->find(iniName));
- if (iFind == p_bootstrap_map->end())
+ auto iFind(bootstrap_map.find(iniName));
+ if (iFind == bootstrap_map.end())
{
- bootstrap_map::release();
guard.clear();
that = new Bootstrap_Impl(iniName);
guard.reset();
- p_bootstrap_map = bootstrap_map::get();
- iFind = p_bootstrap_map->find(iniName);
- if (iFind == p_bootstrap_map->end())
+ iFind = bootstrap_map.find(iniName);
+ if (iFind == bootstrap_map.end())
{
++that->_nRefCount;
- ::std::pair< bootstrap_map::t::iterator, bool > insertion(
- p_bootstrap_map->emplace(iniName, that));
+ ::std::pair< bootstrap_map_t::iterator, bool > insertion(
+ bootstrap_map.emplace(iniName, that));
OSL_ASSERT(insertion.second);
}
else
@@ -675,23 +644,21 @@ void SAL_CALL rtl_bootstrap_args_close(rtlBootstrapHandle handle) SAL_THROW_EXTE
Bootstrap_Impl * that = static_cast< Bootstrap_Impl * >( handle );
osl::MutexGuard guard(osl::Mutex::getGlobalMutex());
- bootstrap_map::t* p_bootstrap_map = bootstrap_map::get();
- OSL_ASSERT(p_bootstrap_map->find(that->_iniName)->second == that);
+ OSL_ASSERT(bootstrap_map.find(that->_iniName)->second == that);
--that->_nRefCount;
if (that->_nRefCount != 0)
return;
std::size_t const nLeaking = 8; // only hold up to 8 files statically
- if (p_bootstrap_map->size() > nLeaking)
+ if (bootstrap_map.size() > nLeaking)
{
- ::std::size_t erased = p_bootstrap_map->erase( that->_iniName );
+ ::std::size_t erased = bootstrap_map.erase( that->_iniName );
if (erased != 1) {
OSL_ASSERT( false );
}
delete that;
}
- bootstrap_map::release();
}
sal_Bool SAL_CALL rtl_bootstrap_get_from_handle(