summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2023-02-26 20:37:34 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2023-02-27 05:43:11 +0000
commit09680fadbcd85da3405cefeed66712bc0ba2be9c (patch)
tree56e32ecc03bf9f4e3a484af5150bc58abeae3fb6
parent44a3085f9aaf0dfc62b1a8f34d3b8889d69c4e62 (diff)
no need to hold CollatorWrapper by std::unique_ptr
allocate it inline, it is only one pointer in size Change-Id: Idb6217e6c9c37da92427aa6c497223a84015c553 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147742 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--cui/source/inc/autocdlg.hxx6
-rw-r--r--cui/source/tabpages/autocdlg.cxx30
-rw-r--r--desktop/source/deployment/gui/dp_gui_extlistbox.cxx10
-rw-r--r--desktop/source/deployment/gui/dp_gui_extlistbox.hxx3
-rw-r--r--include/unotools/intlwrapper.hxx15
-rw-r--r--sc/source/ui/dbgui/tpsort.cxx6
-rw-r--r--sc/source/ui/inc/tpsort.hxx2
-rw-r--r--unotools/source/i18n/intlwrapper.cxx9
8 files changed, 41 insertions, 40 deletions
diff --git a/cui/source/inc/autocdlg.hxx b/cui/source/inc/autocdlg.hxx
index a1a6146fa1bb..8e31011e7a33 100644
--- a/cui/source/inc/autocdlg.hxx
+++ b/cui/source/inc/autocdlg.hxx
@@ -20,13 +20,13 @@
#include <sfx2/tabdlg.hxx>
#include <svx/langbox.hxx>
+#include <unotools/collatorwrapper.hxx>
#include <map>
#include <set>
#include <utility>
class CharClass;
-class CollatorWrapper;
class SmartTagMgr;
namespace editeng { class SortedAutoCompleteStrings; }
@@ -166,7 +166,7 @@ private:
std::set<OUString> aFormatText;
std::map<LanguageType, DoubleStringArray>
aDoubleStringTable;
- std::unique_ptr<CollatorWrapper> pCompareClass;
+ std::optional<CollatorWrapper> moCompareClass;
std::unique_ptr<CharClass> pCharClass;
LanguageType eLang;
@@ -227,7 +227,7 @@ class OfaAutocorrExceptPage : public SfxTabPage
{
private:
StringsTable aStringsTable;
- std::unique_ptr<CollatorWrapper> pCompareClass;
+ std::optional<CollatorWrapper> moCompareClass;
LanguageType eLang;
std::unique_ptr<weld::Entry> m_xAbbrevED;
diff --git a/cui/source/tabpages/autocdlg.cxx b/cui/source/tabpages/autocdlg.cxx
index bc3f3bcc7be7..21716d43a1a9 100644
--- a/cui/source/tabpages/autocdlg.cxx
+++ b/cui/source/tabpages/autocdlg.cxx
@@ -696,8 +696,8 @@ OfaAutocorrReplacePage::OfaAutocorrReplacePage(weld::Container* pPage, weld::Dia
bSWriter = pMod == SfxModule::GetActiveModule();
LanguageTag aLanguageTag( eLastDialogLanguage );
- pCompareClass.reset( new CollatorWrapper( comphelper::getProcessComponentContext() ) );
- pCompareClass->loadDefaultCollator( aLanguageTag.getLocale(), 0 );
+ moCompareClass.emplace( comphelper::getProcessComponentContext() );
+ moCompareClass->loadDefaultCollator( aLanguageTag.getLocale(), 0 );
pCharClass.reset( new CharClass( std::move(aLanguageTag) ) );
auto nColWidth = m_xReplaceTLB->get_approximate_digit_width() * 32;
@@ -720,7 +720,7 @@ OfaAutocorrReplacePage::~OfaAutocorrReplacePage()
aDoubleStringTable.clear();
aChangesTable.clear();
- pCompareClass.reset();
+ moCompareClass.reset();
pCharClass.reset();
}
@@ -902,8 +902,8 @@ void OfaAutocorrReplacePage::SetLanguage(LanguageType eSet)
eLastDialogLanguage = eSet;
LanguageTag aLanguageTag( eLastDialogLanguage );
- pCompareClass.reset( new CollatorWrapper( comphelper::getProcessComponentContext() ) );
- pCompareClass->loadDefaultCollator( aLanguageTag.getLocale(), 0 );
+ moCompareClass.emplace( comphelper::getProcessComponentContext() );
+ moCompareClass->loadDefaultCollator( aLanguageTag.getLocale(), 0 );
pCharClass.reset( new CharClass( std::move(aLanguageTag) ) );
ModifyHdl(*m_xShortED);
}
@@ -917,7 +917,7 @@ IMPL_LINK(OfaAutocorrReplacePage, SelectHdl, weld::TreeView&, rBox, void)
OUString sTmpShort(rBox.get_text(nEntry, 0));
// if the text is set via ModifyHdl, the cursor is always at the beginning
// of a word, although you're editing here
- bool bSameContent = 0 == pCompareClass->compareString(sTmpShort, m_xShortED->get_text());
+ bool bSameContent = 0 == moCompareClass->compareString(sTmpShort, m_xShortED->get_text());
int nStartPos, nEndPos;
m_xShortED->get_selection_bounds(nStartPos, nEndPos);
if (m_xShortED->get_text() != sTmpShort)
@@ -1055,7 +1055,7 @@ bool OfaAutocorrReplacePage::NewDelHdl(const weld::Widget* pBtn)
int nCount = m_xReplaceTLB->n_children();
for (j = 0; j < nCount; ++j)
{
- if (0 >= pCompareClass->compareString(sEntry, m_xReplaceTLB->get_text(j, 0)))
+ if (0 >= moCompareClass->compareString(sEntry, m_xReplaceTLB->get_text(j, 0)))
break;
}
nPos = j;
@@ -1108,7 +1108,7 @@ IMPL_LINK(OfaAutocorrReplacePage, ModifyHdl, weld::Entry&, rEdt, void)
&bTmpSelEntry, &bFirstSelIterSet,
&xFirstSel, &aWordStr](weld::TreeIter& rIter){
OUString aTestStr = m_xReplaceTLB->get_text(rIter, 0);
- if( pCompareClass->compareString(rEntry, aTestStr ) == 0 )
+ if( moCompareClass->compareString(rEntry, aTestStr ) == 0 )
{
if (!rRepString.isEmpty())
bFirstSelect = true;
@@ -1208,8 +1208,8 @@ OfaAutocorrExceptPage::OfaAutocorrExceptPage(weld::Container* pPage, weld::Dialo
m_xDoubleCapsLB->set_size_request(-1, m_xDoubleCapsLB->get_height_rows(6));
css::lang::Locale aLcl( LanguageTag::convertToLocale(eLastDialogLanguage ));
- pCompareClass.reset( new CollatorWrapper( comphelper::getProcessComponentContext() ) );
- pCompareClass->loadDefaultCollator( aLcl, 0 );
+ moCompareClass.emplace( comphelper::getProcessComponentContext() );
+ moCompareClass->loadDefaultCollator( aLcl, 0 );
m_xNewAbbrevPB->connect_clicked(LINK(this, OfaAutocorrExceptPage, NewDelButtonHdl));
m_xDelAbbrevPB->connect_clicked(LINK(this, OfaAutocorrExceptPage, NewDelButtonHdl));
@@ -1228,7 +1228,7 @@ OfaAutocorrExceptPage::OfaAutocorrExceptPage(weld::Container* pPage, weld::Dialo
OfaAutocorrExceptPage::~OfaAutocorrExceptPage()
{
aStringsTable.clear();
- pCompareClass.reset();
+ moCompareClass.reset();
}
std::unique_ptr<SfxTabPage> OfaAutocorrExceptPage::Create(weld::Container* pPage, weld::DialogController* pController,
@@ -1363,8 +1363,8 @@ void OfaAutocorrExceptPage::SetLanguage(LanguageType eSet)
// save old settings and fill anew
RefillReplaceBoxes(false, eLang, eSet);
eLastDialogLanguage = eSet;
- pCompareClass.reset( new CollatorWrapper( comphelper::getProcessComponentContext() ) );
- pCompareClass->loadDefaultCollator( LanguageTag::convertToLocale( eLastDialogLanguage ), 0 );
+ moCompareClass.emplace( comphelper::getProcessComponentContext() );
+ moCompareClass->loadDefaultCollator( LanguageTag::convertToLocale( eLastDialogLanguage ), 0 );
ModifyHdl(*m_xAbbrevED);
ModifyHdl(*m_xDoubleCapsED);
}
@@ -1509,7 +1509,7 @@ IMPL_LINK(OfaAutocorrExceptPage, ModifyHdl, weld::Entry&, rEdt, void)
bool bEntryLen = !sEntry.isEmpty();
if (&rEdt == m_xAbbrevED.get())
{
- bool bSame = lcl_FindEntry(*m_xAbbrevLB, sEntry, *pCompareClass);
+ bool bSame = lcl_FindEntry(*m_xAbbrevLB, sEntry, *moCompareClass);
if(bSame && sEntry != m_xAbbrevLB->get_selected_text())
rEdt.set_text(m_xAbbrevLB->get_selected_text());
m_xNewAbbrevPB->set_sensitive(!bSame && bEntryLen);
@@ -1517,7 +1517,7 @@ IMPL_LINK(OfaAutocorrExceptPage, ModifyHdl, weld::Entry&, rEdt, void)
}
else
{
- bool bSame = lcl_FindEntry(*m_xDoubleCapsLB, sEntry, *pCompareClass);
+ bool bSame = lcl_FindEntry(*m_xDoubleCapsLB, sEntry, *moCompareClass);
if(bSame && sEntry != m_xDoubleCapsLB->get_selected_text())
rEdt.set_text(m_xDoubleCapsLB->get_selected_text());
m_xNewDoublePB->set_sensitive(!bSame && bEntryLen);
diff --git a/desktop/source/deployment/gui/dp_gui_extlistbox.cxx b/desktop/source/deployment/gui/dp_gui_extlistbox.cxx
index d30d24f79166..f21585c3e402 100644
--- a/desktop/source/deployment/gui/dp_gui_extlistbox.cxx
+++ b/desktop/source/deployment/gui/dp_gui_extlistbox.cxx
@@ -220,8 +220,8 @@ void ExtensionBox_Impl::Init()
m_xRemoveListener = new ExtensionRemovedListener( this );
m_pLocale.reset( new lang::Locale( Application::GetSettings().GetLanguageTag().getLocale() ) );
- m_pCollator.reset( new CollatorWrapper( ::comphelper::getProcessComponentContext() ) );
- m_pCollator->loadDefaultCollator( *m_pLocale, i18n::CollatorOptions::CollatorOptions_IGNORE_CASE );
+ m_oCollator.emplace( ::comphelper::getProcessComponentContext() );
+ m_oCollator->loadDefaultCollator( *m_pLocale, i18n::CollatorOptions::CollatorOptions_IGNORE_CASE );
}
ExtensionBox_Impl::~ExtensionBox_Impl()
@@ -241,7 +241,7 @@ ExtensionBox_Impl::~ExtensionBox_Impl()
m_xRemoveListener.clear();
m_pLocale.reset();
- m_pCollator.reset();
+ m_oCollator.reset();
}
sal_Int32 ExtensionBox_Impl::getItemCount() const
@@ -826,7 +826,7 @@ bool ExtensionBox_Impl::FindEntryPos( const TEntry_Impl& rEntry, const tools::Lo
if ( nStart == nEnd )
{
- eCompare = rEntry->CompareTo( m_pCollator.get(), m_vEntries[ nStart ] );
+ eCompare = rEntry->CompareTo( &*m_oCollator, m_vEntries[ nStart ] );
if ( eCompare < 0 )
return false;
else if ( eCompare == 0 )
@@ -847,7 +847,7 @@ bool ExtensionBox_Impl::FindEntryPos( const TEntry_Impl& rEntry, const tools::Lo
}
const tools::Long nMid = nStart + ( ( nEnd - nStart ) / 2 );
- eCompare = rEntry->CompareTo( m_pCollator.get(), m_vEntries[ nMid ] );
+ eCompare = rEntry->CompareTo( &*m_oCollator, m_vEntries[ nMid ] );
if ( eCompare < 0 )
return FindEntryPos( rEntry, nStart, nMid-1, nPos );
diff --git a/desktop/source/deployment/gui/dp_gui_extlistbox.hxx b/desktop/source/deployment/gui/dp_gui_extlistbox.hxx
index d706975dcdfd..cfc04f115d22 100644
--- a/desktop/source/deployment/gui/dp_gui_extlistbox.hxx
+++ b/desktop/source/deployment/gui/dp_gui_extlistbox.hxx
@@ -33,6 +33,7 @@
#include <com/sun/star/deployment/XPackage.hpp>
#include <memory>
+#include <optional>
#include "dp_gui.h"
@@ -137,7 +138,7 @@ class ExtensionBox_Impl : public weld::CustomWidgetController
std::vector< TEntry_Impl > m_vRemovedEntries;
std::unique_ptr<css::lang::Locale> m_pLocale;
- std::unique_ptr<CollatorWrapper> m_pCollator;
+ std::optional<CollatorWrapper> m_oCollator;
//Holds weak references to extensions to which is we have added an XEventListener
std::vector< css::uno::WeakReference<
diff --git a/include/unotools/intlwrapper.hxx b/include/unotools/intlwrapper.hxx
index e86346a9552e..0c473cc4293f 100644
--- a/include/unotools/intlwrapper.hxx
+++ b/include/unotools/intlwrapper.hxx
@@ -21,14 +21,15 @@
#define INCLUDED_UNOTOOLS_INTLWRAPPER_HXX
#include <unotools/unotoolsdllapi.h>
+#include <unotools/collatorwrapper.hxx>
#include <com/sun/star/uno/Reference.h>
#include <i18nlangtag/languagetag.hxx>
#include <memory>
+#include <optional>
namespace com::sun::star::uno { class XComponentContext; }
-class CollatorWrapper;
class LocaleDataWrapper;
/**
@@ -54,8 +55,8 @@ private:
css::uno::Reference< css::uno::XComponentContext > m_xContext;
std::unique_ptr<LocaleDataWrapper> pLocaleData;
- std::unique_ptr<CollatorWrapper> pCollator;
- std::unique_ptr<CollatorWrapper> pCaseCollator;
+ std::optional<CollatorWrapper> moCollator;
+ std::optional<CollatorWrapper> moCaseCollator;
void ImplNewLocaleData() const;
void ImplNewCollator( bool bCaseSensitive ) const;
@@ -73,16 +74,16 @@ public:
/// case insensitive collator, simple IGNORE_CASE
const CollatorWrapper* getCollator() const
{
- if ( !pCollator )
+ if ( !moCollator )
ImplNewCollator( false );
- return pCollator.get();
+ return &*moCollator;
}
/// case sensitive collator
const CollatorWrapper* getCaseCollator() const
{
- if ( !pCaseCollator )
+ if ( !moCaseCollator )
ImplNewCollator( true );
- return pCaseCollator.get();
+ return &*moCaseCollator;
}
};
diff --git a/sc/source/ui/dbgui/tpsort.cxx b/sc/source/ui/dbgui/tpsort.cxx
index 35a24e633058..88d6cf6472e2 100644
--- a/sc/source/ui/dbgui/tpsort.cxx
+++ b/sc/source/ui/dbgui/tpsort.cxx
@@ -522,7 +522,7 @@ void ScTabPageSortOptions::Init()
m_xColRes.reset(new CollatorResource);
//! use CollatorWrapper from document?
- m_xColWrap.reset(new CollatorWrapper(comphelper::getProcessComponentContext()));
+ m_oColWrap.emplace(comphelper::getProcessComponentContext());
const ScSortItem& rSortItem = GetItemSet().Get( nWhichSort );
@@ -660,7 +660,7 @@ bool ScTabPageSortOptions::FillItemSet( SfxItemSet* rArgSet )
OUString sAlg;
if ( eLang != LANGUAGE_SYSTEM )
{
- uno::Sequence<OUString> aAlgos = m_xColWrap->listCollatorAlgorithms(
+ uno::Sequence<OUString> aAlgos = m_oColWrap->listCollatorAlgorithms(
aNewSortData.aCollatorLocale );
const int nSel = m_xLbAlgorithm->get_active();
if ( nSel < aAlgos.getLength() )
@@ -830,7 +830,7 @@ void ScTabPageSortOptions::FillAlgor()
else
{
lang::Locale aLocale( LanguageTag::convertToLocale( eLang ));
- const uno::Sequence<OUString> aAlgos = m_xColWrap->listCollatorAlgorithms( aLocale );
+ const uno::Sequence<OUString> aAlgos = m_oColWrap->listCollatorAlgorithms( aLocale );
nCount = aAlgos.getLength();
for (const OUString& sAlg : aAlgos)
diff --git a/sc/source/ui/inc/tpsort.hxx b/sc/source/ui/inc/tpsort.hxx
index 655f3a7732ed..4e6a36ca9da5 100644
--- a/sc/source/ui/inc/tpsort.hxx
+++ b/sc/source/ui/inc/tpsort.hxx
@@ -121,7 +121,7 @@ private:
ScAddress theOutPos;
std::unique_ptr<CollatorResource> m_xColRes;
- std::unique_ptr<CollatorWrapper> m_xColWrap;
+ std::optional<CollatorWrapper> m_oColWrap;
std::unique_ptr<weld::CheckButton> m_xBtnCase;
std::unique_ptr<weld::CheckButton> m_xBtnFormats;
diff --git a/unotools/source/i18n/intlwrapper.cxx b/unotools/source/i18n/intlwrapper.cxx
index a4c21ea940aa..19157dab4a67 100644
--- a/unotools/source/i18n/intlwrapper.cxx
+++ b/unotools/source/i18n/intlwrapper.cxx
@@ -42,17 +42,16 @@ void IntlWrapper::ImplNewLocaleData() const
void IntlWrapper::ImplNewCollator( bool bCaseSensitive ) const
{
- CollatorWrapper* p = new CollatorWrapper( m_xContext );
if ( bCaseSensitive )
{
- p->loadDefaultCollator( maLanguageTag.getLocale(), 0 );
- const_cast<IntlWrapper*>(this)->pCaseCollator.reset(p);
+ const_cast<IntlWrapper*>(this)->moCaseCollator.emplace(m_xContext);
+ const_cast<IntlWrapper*>(this)->moCaseCollator->loadDefaultCollator( maLanguageTag.getLocale(), 0 );
}
else
{
- p->loadDefaultCollator( maLanguageTag.getLocale(),
+ const_cast<IntlWrapper*>(this)->moCollator.emplace(m_xContext);
+ const_cast<IntlWrapper*>(this)->moCollator->loadDefaultCollator( maLanguageTag.getLocale(),
css::i18n::CollatorOptions::CollatorOptions_IGNORE_CASE );
- const_cast<IntlWrapper*>(this)->pCollator.reset(p);
}
}