Optimize ScAppCfg::ReadSortListCfg

Do not initialize defaults when using custom user list.

Change-Id: I8428a20b65182011a25325f0b7298ea51998346b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152587
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
diff --git a/sc/inc/userlist.hxx b/sc/inc/userlist.hxx
index 7625ad1..8096836 100644
--- a/sc/inc/userlist.hxx
+++ b/sc/inc/userlist.hxx
@@ -69,9 +69,10 @@ class SC_DLLPUBLIC ScUserList
    DataType maData;

public:
    ScUserList();
    explicit ScUserList(bool initDefault = true);
    ScUserList(const ScUserList& r) = default;

    void AddDefaults();
    void EraseData(size_t nIndex) { maData.erase(maData.cbegin() + nIndex); }

    const ScUserListData* GetData(const OUString& rSubStr) const;
diff --git a/sc/source/core/tool/appoptio.cxx b/sc/source/core/tool/appoptio.cxx
index 16a0c4cb..9dbc85f 100644
--- a/sc/source/core/tool/appoptio.cxx
+++ b/sc/source/core/tool/appoptio.cxx
@@ -407,16 +407,18 @@ void ScAppCfg::ReadSortListCfg()

    if (Sequence<OUString> aSeq; aValues[SCSORTLISTOPT_LIST] >>= aSeq)
    {
        ScUserList aList;
        ScUserList aList(false); // Do not init defaults

        //  if setting is "default", keep default values from ScUserList ctor
        //  if setting is "default", keep default values
        //TODO: mark "default" in a safe way
        const bool bDefault = (aSeq.getLength() == 1 && aSeq[0] == "NULL");

        if (!bDefault)
        if (bDefault)
        {
            aList.clear();

            aList.AddDefaults();
        }
        else
        {
            for (const OUString& rStr : std::as_const(aSeq))
            {
                aList.emplace_back(rStr);
diff --git a/sc/source/core/tool/userlist.cxx b/sc/source/core/tool/userlist.cxx
index 4540ad3e..f38a16d 100644
--- a/sc/source/core/tool/userlist.cxx
+++ b/sc/source/core/tool/userlist.cxx
@@ -200,20 +200,18 @@ sal_Int32 ScUserListData::ICompare(const OUString& rSubStr1, const OUString& rSu
        return ScGlobal::GetTransliteration().compareString( rSubStr1, rSubStr2 );
}

ScUserList::ScUserList()
ScUserList::ScUserList(bool initDefault)
{
    using namespace ::com::sun::star;
    if (initDefault)
        AddDefaults();
}

void ScUserList::AddDefaults()
{
    sal_Unicode cDelimiter = ScGlobal::cListDelimiter;
    uno::Sequence< i18n::CalendarItem2 > xCal;

    const uno::Sequence< i18n::Calendar2 > xCalendars(
            ScGlobal::getLocaleData().getAllCalendars() );

    for ( const auto& rCalendar : xCalendars )
    for (const auto& rCalendar : ScGlobal::getLocaleData().getAllCalendars())
    {
        xCal = rCalendar.Days;
        if ( xCal.hasElements() )
        if (const auto& xCal = rCalendar.Days; xCal.hasElements())
        {
            OUStringBuffer aDayShortBuf(32), aDayLongBuf(64);
            sal_Int32 i;
@@ -244,8 +242,7 @@ ScUserList::ScUserList()
                emplace_back(aDayLong);
        }

        xCal = rCalendar.Months;
        if ( xCal.hasElements() )
        if (const auto& xCal = rCalendar.Months; xCal.hasElements())
        {
            OUStringBuffer aMonthShortBuf(128), aMonthLongBuf(128);
            sal_Int32 i;