summaryrefslogtreecommitdiff
path: root/editeng
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2022-09-01 19:02:04 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-09-02 12:39:08 +0200
commitb467c7a12bd5e5e2862a8c018a2135635dcc50cb (patch)
tree6008880e7966ae442599f45891f68c04af4af9d4 /editeng
parentd0176d65de40b1ea53b4fcbc0f607911fa64d8e5 (diff)
no need to use unique_ptr for this map in SvxAutoCorrect
map is already a node based data structure, so the values will stay in the same place in memory Change-Id: I26ac04787a3b36feebd574687710b3a2b6864c0e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139234 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'editeng')
-rw-r--r--editeng/source/misc/svxacorr.cxx75
1 files changed, 39 insertions, 36 deletions
diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx
index 4ee4f61a0d33..14c4236f0d28 100644
--- a/editeng/source/misc/svxacorr.cxx
+++ b/editeng/source/misc/svxacorr.cxx
@@ -18,6 +18,7 @@
*/
#include <memory>
+#include <utility>
#include <string_view>
#include <sal/config.h>
@@ -1633,14 +1634,14 @@ SvxAutoCorrectLanguageLists& SvxAutoCorrect::GetLanguageList_(
LanguageTag aLanguageTag( eLang);
if (m_aLangTable.find(aLanguageTag) == m_aLangTable.end())
(void)CreateLanguageFile(aLanguageTag);
- return *(m_aLangTable.find(aLanguageTag)->second);
+ return m_aLangTable.find(aLanguageTag)->second;
}
void SvxAutoCorrect::SaveCplSttExceptList( LanguageType eLang )
{
auto const iter = m_aLangTable.find(LanguageTag(eLang));
- if (iter != m_aLangTable.end() && iter->second)
- iter->second->SaveCplSttExceptList();
+ if (iter != m_aLangTable.end())
+ iter->second.SaveCplSttExceptList();
else
{
SAL_WARN("editeng", "Save an empty list? ");
@@ -1650,8 +1651,8 @@ void SvxAutoCorrect::SaveCplSttExceptList( LanguageType eLang )
void SvxAutoCorrect::SaveWordStartExceptList(LanguageType eLang)
{
auto const iter = m_aLangTable.find(LanguageTag(eLang));
- if (iter != m_aLangTable.end() && iter->second)
- iter->second->SaveWordStartExceptList();
+ if (iter != m_aLangTable.end())
+ iter->second.SaveWordStartExceptList();
else
{
SAL_WARN("editeng", "Save an empty list? ");
@@ -1666,15 +1667,15 @@ bool SvxAutoCorrect::AddCplSttException( const OUString& rNew,
// either the right language is present or it will be this in the general list
auto iter = m_aLangTable.find(LanguageTag(eLang));
if (iter != m_aLangTable.end())
- pLists = iter->second.get();
+ pLists = &iter->second;
else
{
LanguageTag aLangTagUndetermined( LANGUAGE_UNDETERMINED);
iter = m_aLangTable.find(aLangTagUndetermined);
if (iter != m_aLangTable.end())
- pLists = iter->second.get();
+ pLists = &iter->second;
else if(CreateLanguageFile(aLangTagUndetermined))
- pLists = m_aLangTable.find(aLangTagUndetermined)->second.get();
+ pLists = &m_aLangTable.find(aLangTagUndetermined)->second;
}
OSL_ENSURE(pLists, "No auto correction data");
return pLists && pLists->AddToCplSttExceptList(rNew);
@@ -1688,15 +1689,15 @@ bool SvxAutoCorrect::AddWordStartException( const OUString& rNew,
//either the right language is present or it is set in the general list
auto iter = m_aLangTable.find(LanguageTag(eLang));
if (iter != m_aLangTable.end())
- pLists = iter->second.get();
+ pLists = &iter->second;
else
{
LanguageTag aLangTagUndetermined( LANGUAGE_UNDETERMINED);
iter = m_aLangTable.find(aLangTagUndetermined);
if (iter != m_aLangTable.end())
- pLists = iter->second.get();
+ pLists = &iter->second;
else if(CreateLanguageFile(aLangTagUndetermined))
- pLists = m_aLangTable.find(aLangTagUndetermined)->second.get();
+ pLists = &m_aLangTable.find(aLangTagUndetermined)->second;
}
OSL_ENSURE(pLists, "No auto correction file!");
return pLists && pLists->AddToWordStartExceptList(rNew);
@@ -1799,9 +1800,10 @@ bool SvxAutoCorrect::CreateLanguageFile( const LanguageTag& rLanguageTag, bool b
if( bNewFile )
{
sShareDirFile = sUserDirFile;
- pLists = new SvxAutoCorrectLanguageLists( *this, sShareDirFile, sUserDirFile );
- LanguageTag aTmp(rLanguageTag); // this insert() needs a non-const reference
- m_aLangTable.insert(std::make_pair(aTmp, std::unique_ptr<SvxAutoCorrectLanguageLists>(pLists)));
+ auto itBool = m_aLangTable.emplace(std::piecewise_construct,
+ std::forward_as_tuple(rLanguageTag),
+ std::forward_as_tuple(*this, sShareDirFile, sUserDirFile));
+ pLists = &itBool.first->second;
aLastFileTable.erase(nFndPos);
}
}
@@ -1815,9 +1817,10 @@ bool SvxAutoCorrect::CreateLanguageFile( const LanguageTag& rLanguageTag, bool b
( sShareDirFile = sUserDirFile, bNewFile )
)
{
- pLists = new SvxAutoCorrectLanguageLists( *this, sShareDirFile, sUserDirFile );
- LanguageTag aTmp(rLanguageTag); // this insert() needs a non-const reference
- m_aLangTable.insert(std::make_pair(aTmp, std::unique_ptr<SvxAutoCorrectLanguageLists>(pLists)));
+ auto itBool = m_aLangTable.emplace(std::piecewise_construct,
+ std::forward_as_tuple(rLanguageTag),
+ std::forward_as_tuple(*this, sShareDirFile, sUserDirFile));
+ pLists = &itBool.first->second;
if (nFndPos != aLastFileTable.end())
aLastFileTable.erase(nFndPos);
}
@@ -1834,9 +1837,9 @@ bool SvxAutoCorrect::PutText( const OUString& rShort, const OUString& rLong,
LanguageTag aLanguageTag( eLang);
auto const iter = m_aLangTable.find(aLanguageTag);
if (iter != m_aLangTable.end())
- return iter->second->PutText(rShort, rLong);
+ return iter->second.PutText(rShort, rLong);
if(CreateLanguageFile(aLanguageTag))
- return m_aLangTable.find(aLanguageTag)->second->PutText(rShort, rLong);
+ return m_aLangTable.find(aLanguageTag)->second.PutText(rShort, rLong);
return false;
}
@@ -1848,11 +1851,11 @@ void SvxAutoCorrect::MakeCombinedChanges( std::vector<SvxAutocorrWord>& aNewEntr
auto const iter = m_aLangTable.find(aLanguageTag);
if (iter != m_aLangTable.end())
{
- iter->second->MakeCombinedChanges( aNewEntries, aDeleteEntries );
+ iter->second.MakeCombinedChanges( aNewEntries, aDeleteEntries );
}
else if(CreateLanguageFile( aLanguageTag ))
{
- m_aLangTable.find( aLanguageTag )->second->MakeCombinedChanges( aNewEntries, aDeleteEntries );
+ m_aLangTable.find( aLanguageTag )->second.MakeCombinedChanges( aNewEntries, aDeleteEntries );
}
}
@@ -1937,8 +1940,8 @@ const SvxAutocorrWord* SvxAutoCorrect::SearchWordsInList(
if (m_aLangTable.find(aLanguageTag) != m_aLangTable.end() || CreateLanguageFile(aLanguageTag, false))
{
//the language is available - so bring it on
- std::unique_ptr<SvxAutoCorrectLanguageLists> const& pList = m_aLangTable.find(aLanguageTag)->second;
- pRet = lcl_SearchWordsInList( pList.get(), rTxt, rStt, nEndPos );
+ SvxAutoCorrectLanguageLists & rList = m_aLangTable.find(aLanguageTag)->second;
+ pRet = lcl_SearchWordsInList( &rList, rTxt, rStt, nEndPos );
if( pRet )
{
rLang = aLanguageTag;
@@ -1958,8 +1961,8 @@ const SvxAutocorrWord* SvxAutoCorrect::SearchWordsInList(
CreateLanguageFile(aLanguageTag, false)))
{
//the language is available - so bring it on
- std::unique_ptr<SvxAutoCorrectLanguageLists> const& pList = m_aLangTable.find(aLanguageTag)->second;
- pRet = lcl_SearchWordsInList( pList.get(), rTxt, rStt, nEndPos );
+ SvxAutoCorrectLanguageLists& rList = m_aLangTable.find(aLanguageTag)->second;
+ pRet = lcl_SearchWordsInList( &rList, rTxt, rStt, nEndPos );
if( pRet )
{
rLang = aLanguageTag;
@@ -1971,8 +1974,8 @@ const SvxAutocorrWord* SvxAutoCorrect::SearchWordsInList(
CreateLanguageFile(aLanguageTag, false))
{
//the language is available - so bring it on
- std::unique_ptr<SvxAutoCorrectLanguageLists> const& pList = m_aLangTable.find(aLanguageTag)->second;
- pRet = lcl_SearchWordsInList( pList.get(), rTxt, rStt, nEndPos );
+ SvxAutoCorrectLanguageLists& rList = m_aLangTable.find(aLanguageTag)->second;
+ pRet = lcl_SearchWordsInList( &rList, rTxt, rStt, nEndPos );
if( pRet )
{
rLang = aLanguageTag;
@@ -1995,8 +1998,8 @@ bool SvxAutoCorrect::FindInWordStartExceptList( LanguageType eLang,
if (m_aLangTable.find(aLanguageTag) != m_aLangTable.end() || CreateLanguageFile(aLanguageTag, false))
{
//the language is available - so bring it on
- auto const& pList = m_aLangTable.find(aLanguageTag)->second;
- if(pList->GetWordStartExceptList()->find(sWord) != pList->GetWordStartExceptList()->end() )
+ auto& rList = m_aLangTable.find(aLanguageTag)->second;
+ if(rList.GetWordStartExceptList()->find(sWord) != rList.GetWordStartExceptList()->end() )
return true;
}
@@ -2009,8 +2012,8 @@ bool SvxAutoCorrect::FindInWordStartExceptList( LanguageType eLang,
CreateLanguageFile(aLanguageTag, false)))
{
//the language is available - so bring it on
- auto const& pList = m_aLangTable.find(aLanguageTag)->second;
- if(pList->GetWordStartExceptList()->find(sWord) != pList->GetWordStartExceptList()->end() )
+ auto& rList = m_aLangTable.find(aLanguageTag)->second;
+ if(rList.GetWordStartExceptList()->find(sWord) != rList.GetWordStartExceptList()->end() )
return true;
}
@@ -2018,8 +2021,8 @@ bool SvxAutoCorrect::FindInWordStartExceptList( LanguageType eLang,
CreateLanguageFile(aLanguageTag, false))
{
//the language is available - so bring it on
- auto const& pList = m_aLangTable.find(aLanguageTag)->second;
- if(pList->GetWordStartExceptList()->find(sWord) != pList->GetWordStartExceptList()->end() )
+ auto& rList = m_aLangTable.find(aLanguageTag)->second;
+ if(rList.GetWordStartExceptList()->find(sWord) != rList.GetWordStartExceptList()->end() )
return true;
}
return false;
@@ -2071,7 +2074,7 @@ bool SvxAutoCorrect::FindInCplSttExceptList(LanguageType eLang,
if (m_aLangTable.find(aLanguageTag) != m_aLangTable.end() || CreateLanguageFile(aLanguageTag, false))
{
//the language is available - so bring it on
- const SvStringsISortDtor* pList = m_aLangTable.find(aLanguageTag)->second->GetCplSttExceptList();
+ const SvStringsISortDtor* pList = m_aLangTable.find(aLanguageTag)->second.GetCplSttExceptList();
if(bAbbreviation ? lcl_FindAbbreviation(pList, sWord) : pList->find(sWord) != pList->end() )
return true;
}
@@ -2085,7 +2088,7 @@ bool SvxAutoCorrect::FindInCplSttExceptList(LanguageType eLang,
CreateLanguageFile(aLanguageTag, false)))
{
//the language is available - so bring it on
- const SvStringsISortDtor* pList = m_aLangTable.find(aLanguageTag)->second->GetCplSttExceptList();
+ const SvStringsISortDtor* pList = m_aLangTable.find(aLanguageTag)->second.GetCplSttExceptList();
if(bAbbreviation ? lcl_FindAbbreviation(pList, sWord) : pList->find(sWord) != pList->end() )
return true;
}
@@ -2094,7 +2097,7 @@ bool SvxAutoCorrect::FindInCplSttExceptList(LanguageType eLang,
CreateLanguageFile(aLanguageTag, false))
{
//the language is available - so bring it on
- const SvStringsISortDtor* pList = m_aLangTable.find(aLanguageTag)->second->GetCplSttExceptList();
+ const SvStringsISortDtor* pList = m_aLangTable.find(aLanguageTag)->second.GetCplSttExceptList();
if(bAbbreviation ? lcl_FindAbbreviation(pList, sWord) : pList->find(sWord) != pList->end() )
return true;
}