diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2021-11-27 22:03:28 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2021-11-29 13:52:28 +0100 |
commit | d4f1531b6d37153384e5a439dab6ab11ae3022ef (patch) | |
tree | d2993d568ba33fadb7a4fe71fdd40f11a43c980f /sc | |
parent | d7f9079c2877cd712132e71f80e49fd08f6e73d1 (diff) |
store ScQueryEntry simply by value
There's not much point in complicating this by allocating them
dynamically if they're always treated by value anyway.
Change-Id: I8325829201c0ad6c95858916a94c5b4d1d208b1c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126024
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/queryentry.hxx | 2 | ||||
-rw-r--r-- | sc/inc/queryparam.hxx | 3 | ||||
-rw-r--r-- | sc/source/core/data/table3.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/tool/queryparam.cxx | 66 |
4 files changed, 28 insertions, 47 deletions
diff --git a/sc/inc/queryentry.hxx b/sc/inc/queryentry.hxx index 9b0b1cd98124..9798b83df785 100644 --- a/sc/inc/queryentry.hxx +++ b/sc/inc/queryentry.hxx @@ -30,7 +30,7 @@ /** * Each instance of this struct represents a single filtering criteria. */ -struct SC_DLLPUBLIC ScQueryEntry +struct SC_DLLPUBLIC ScQueryEntry final { enum QueryType { diff --git a/sc/inc/queryparam.hxx b/sc/inc/queryparam.hxx index e27399107f3f..8d9dbe01fe0f 100644 --- a/sc/inc/queryparam.hxx +++ b/sc/inc/queryparam.hxx @@ -21,6 +21,7 @@ #include <unotools/textsearch.hxx> #include "address.hxx" +#include "queryentry.hxx" #include "types.hxx" #include <memory> @@ -65,7 +66,7 @@ struct SAL_DLLPUBLIC_RTTI ScQueryParamBase SvNumberFormatter* pFormatter ); protected: - typedef std::vector<std::unique_ptr<ScQueryEntry>> EntriesType; + typedef std::vector<ScQueryEntry> EntriesType; public: typedef EntriesType::const_iterator const_iterator; diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx index 2eae384f397a..0b9e4b3ea082 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -3185,9 +3185,9 @@ bool ScTable::ValidQuery( tools::Long nPos = -1; QueryEvaluator aEval(rDocument, *this, rParam, pbTestEqualCondition != nullptr, pValidQueryCache); ScQueryParam::const_iterator it, itBeg = rParam.begin(), itEnd = rParam.end(); - for (it = itBeg; it != itEnd && (*it)->bDoQuery; ++it) + for (it = itBeg; it != itEnd && it->bDoQuery; ++it) { - const ScQueryEntry& rEntry = **it; + const ScQueryEntry& rEntry = *it; // Short-circuit the test at the end of the loop - if this is SC_AND // and the previous value is false, this value will not be needed. diff --git a/sc/source/core/tool/queryparam.cxx b/sc/source/core/tool/queryparam.cxx index 918bb0d5cdab..694f54226b5e 100644 --- a/sc/source/core/tool/queryparam.cxx +++ b/sc/source/core/tool/queryparam.cxx @@ -38,17 +38,17 @@ class FindByField SCCOLROW mnField; public: explicit FindByField(SCCOLROW nField) : mnField(nField) {} - bool operator() (const std::unique_ptr<ScQueryEntry>& rpEntry) const + bool operator() (const ScQueryEntry& rpEntry) const { - return rpEntry->bDoQuery && rpEntry->nField == mnField; + return rpEntry.bDoQuery && rpEntry.nField == mnField; } }; struct FindUnused { - bool operator() (const std::unique_ptr<ScQueryEntry>& rpEntry) const + bool operator() (const ScQueryEntry& rpEntry) const { - return !rpEntry->bDoQuery; + return !rpEntry.bDoQuery; } }; @@ -73,18 +73,14 @@ ScQueryParamBase::ScQueryParamBase() : bDuplicate(false), mbRangeLookup(false) { - for (size_t i = 0; i < MAXQUERY; ++i) - m_Entries.push_back(std::make_unique<ScQueryEntry>()); + m_Entries.resize(MAXQUERY); } ScQueryParamBase::ScQueryParamBase(const ScQueryParamBase& r) : eSearchType(r.eSearchType), bHasHeader(r.bHasHeader), bByRow(r.bByRow), bInplace(r.bInplace), - bCaseSens(r.bCaseSens), bDuplicate(r.bDuplicate), mbRangeLookup(r.mbRangeLookup) + bCaseSens(r.bCaseSens), bDuplicate(r.bDuplicate), mbRangeLookup(r.mbRangeLookup), + m_Entries(r.m_Entries) { - for (auto const& it : r.m_Entries) - { - m_Entries.push_back(std::make_unique<ScQueryEntry>(*it)); - } } ScQueryParamBase& ScQueryParamBase::operator=(const ScQueryParamBase& r) @@ -98,12 +94,7 @@ ScQueryParamBase& ScQueryParamBase::operator=(const ScQueryParamBase& r) bCaseSens = r.bCaseSens; bDuplicate = r.bDuplicate; mbRangeLookup = r.mbRangeLookup; - - m_Entries.clear(); - for (auto const& it : r.m_Entries) - { - m_Entries.push_back(std::make_unique<ScQueryEntry>(*it)); - } + m_Entries = r.m_Entries; } return *this; } @@ -124,12 +115,12 @@ SCSIZE ScQueryParamBase::GetEntryCount() const const ScQueryEntry& ScQueryParamBase::GetEntry(SCSIZE n) const { - return *m_Entries[n]; + return m_Entries[n]; } ScQueryEntry& ScQueryParamBase::GetEntry(SCSIZE n) { - return *m_Entries[n]; + return m_Entries[n]; } ScQueryEntry& ScQueryParamBase::AppendEntry() @@ -140,11 +131,11 @@ ScQueryEntry& ScQueryParamBase::AppendEntry() if (itr != m_Entries.end()) // Found! - return **itr; + return *itr; // Add a new entry to the end. - m_Entries.push_back(std::make_unique<ScQueryEntry>()); - return *m_Entries.back(); + m_Entries.push_back(ScQueryEntry()); + return m_Entries.back(); } ScQueryEntry* ScQueryParamBase::FindEntryByField(SCCOLROW nField, bool bNew) @@ -155,7 +146,7 @@ ScQueryEntry* ScQueryParamBase::FindEntryByField(SCCOLROW nField, bool bNew) if (itr != m_Entries.end()) { // existing entry found! - return (*itr).get(); + return &*itr; } if (!bNew) @@ -171,9 +162,9 @@ std::vector<ScQueryEntry*> ScQueryParamBase::FindAllEntriesByField(SCCOLROW nFie auto fFind = FindByField(nField); - for (const auto& rxEntry : m_Entries) + for (auto& rxEntry : m_Entries) if (fFind(rxEntry)) - aEntries.push_back(rxEntry.get()); + aEntries.push_back(&rxEntry); return aEntries; } @@ -190,7 +181,7 @@ bool ScQueryParamBase::RemoveEntryByField(SCCOLROW nField) if (m_Entries.size() < MAXQUERY) // Make sure that we have at least MAXQUERY number of entries at // all times. - m_Entries.push_back(std::make_unique<ScQueryEntry>()); + m_Entries.resize(MAXQUERY); bRet = true; } @@ -207,18 +198,7 @@ void ScQueryParamBase::Resize(size_t nNew) if (nNew < MAXQUERY) nNew = MAXQUERY; // never less than MAXQUERY - if (nNew < m_Entries.size()) - { - size_t n = m_Entries.size() - nNew; - for (size_t i = 0; i < n; ++i) - m_Entries.pop_back(); - } - else if (nNew > m_Entries.size()) - { - size_t n = nNew - m_Entries.size(); - for (size_t i = 0; i < n; ++i) - m_Entries.push_back(std::make_unique<ScQueryEntry>()); - } + m_Entries.resize(nNew); } void ScQueryParamBase::FillInExcelSyntax( @@ -340,7 +320,7 @@ void ScQueryParam::Clear() for (auto & itr : m_Entries) { - itr->Clear(); + itr.Clear(); } ClearDestParams(); @@ -366,8 +346,8 @@ bool ScQueryParam::operator==( const ScQueryParam& rOther ) const SCSIZE nEntryCount = GetEntryCount(); SCSIZE nOtherEntryCount = rOther.GetEntryCount(); - while (nUsed<nEntryCount && m_Entries[nUsed]->bDoQuery) ++nUsed; - while (nOtherUsed<nOtherEntryCount && rOther.m_Entries[nOtherUsed]->bDoQuery) + while (nUsed<nEntryCount && m_Entries[nUsed].bDoQuery) ++nUsed; + while (nOtherUsed<nOtherEntryCount && rOther.m_Entries[nOtherUsed].bDoQuery) ++nOtherUsed; if ( (nUsed == nOtherUsed) @@ -389,7 +369,7 @@ bool ScQueryParam::operator==( const ScQueryParam& rOther ) const { bEqual = true; for ( SCSIZE i=0; i<nUsed && bEqual; i++ ) - bEqual = *m_Entries[i] == *rOther.m_Entries[i]; + bEqual = m_Entries[i] == rOther.m_Entries[i]; } return bEqual; } @@ -409,7 +389,7 @@ void ScQueryParam::MoveToDest() nTab = sal::static_int_cast<SCTAB>( nTab + nDifZ ); size_t n = m_Entries.size(); for (size_t i=0; i<n; i++) - m_Entries[i]->nField += nDifX; + m_Entries[i].nField += nDifX; bInplace = true; } |