diff options
author | Caolán McNamara <caolanm@redhat.com> | 2021-08-06 09:59:52 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2021-08-06 12:14:58 +0200 |
commit | 413b80ed1a9d29f394d0746106f5698e65fe23dc (patch) | |
tree | f48c3794421dcf4be10c152427b716155733cbfc /cppu/source/threadpool/current.cxx | |
parent | 6189a79cd3a589a403415d288389780167133797 (diff) |
return a reference instead of a pointer
and remove redundant nullptr OSL_ENSURE check
Change-Id: I19e202c3786386ed6f094504a0e1eb6928aa423a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120105
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'cppu/source/threadpool/current.cxx')
-rw-r--r-- | cppu/source/threadpool/current.cxx | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/cppu/source/threadpool/current.cxx b/cppu/source/threadpool/current.cxx index e163a20be2ec..6a992c6af541 100644 --- a/cppu/source/threadpool/current.cxx +++ b/cppu/source/threadpool/current.cxx @@ -106,33 +106,31 @@ IdContainer::~IdContainer() } } -IdContainer * getIdContainer() +IdContainer& getIdContainer() { static thread_local IdContainer aId; - return &aId; + return aId; } } - extern "C" sal_Bool SAL_CALL uno_setCurrentContext( void * pCurrentContext, rtl_uString * pEnvTypeName, void * pEnvContext ) SAL_THROW_EXTERN_C() { - IdContainer * pId = getIdContainer(); - OSL_ASSERT( pId ); + IdContainer& id = getIdContainer(); // free old one - if (pId->pCurrentContext) + if (id.pCurrentContext) { - (*pId->pCurrentContextEnv->releaseInterface)( - pId->pCurrentContextEnv, pId->pCurrentContext ); - (*pId->pCurrentContextEnv->aBase.release)( - &pId->pCurrentContextEnv->aBase ); - pId->pCurrentContextEnv = nullptr; + (*id.pCurrentContextEnv->releaseInterface)( + id.pCurrentContextEnv, id.pCurrentContext ); + (*id.pCurrentContextEnv->aBase.release)( + &id.pCurrentContextEnv->aBase ); + id.pCurrentContextEnv = nullptr; - pId->pCurrentContext = nullptr; + id.pCurrentContext = nullptr; } if (pCurrentContext) @@ -144,10 +142,10 @@ extern "C" sal_Bool SAL_CALL uno_setCurrentContext( { if (pEnv->pExtEnv) { - pId->pCurrentContextEnv = pEnv->pExtEnv; - (*pId->pCurrentContextEnv->acquireInterface)( - pId->pCurrentContextEnv, pCurrentContext ); - pId->pCurrentContext = pCurrentContext; + id.pCurrentContextEnv = pEnv->pExtEnv; + (*id.pCurrentContextEnv->acquireInterface)( + id.pCurrentContextEnv, pCurrentContext ); + id.pCurrentContext = pCurrentContext; } else { @@ -167,8 +165,7 @@ extern "C" sal_Bool SAL_CALL uno_getCurrentContext( void ** ppCurrentContext, rtl_uString * pEnvTypeName, void * pEnvContext ) SAL_THROW_EXTERN_C() { - IdContainer * pId = getIdContainer(); - OSL_ASSERT( pId ); + IdContainer& id = getIdContainer(); Environment target_env; @@ -189,7 +186,7 @@ extern "C" sal_Bool SAL_CALL uno_getCurrentContext( } // case: null-ref - if (nullptr == pId->pCurrentContext) + if (nullptr == id.pCurrentContext) return true; if (! target_env.is()) @@ -200,12 +197,12 @@ extern "C" sal_Bool SAL_CALL uno_getCurrentContext( return false; } - Mapping mapping(&pId->pCurrentContextEnv->aBase, target_env.get()); + Mapping mapping(&id.pCurrentContextEnv->aBase, target_env.get()); OSL_ASSERT( mapping.is() ); if (! mapping.is()) return false; - mapping.mapInterface(ppCurrentContext, pId->pCurrentContext, ::cppu::get_type_XCurrentContext() ); + mapping.mapInterface(ppCurrentContext, id.pCurrentContext, ::cppu::get_type_XCurrentContext()); return true; } |