sc/inc/column.hxx | 2 +- sc/inc/document.hxx | 2 +- sc/inc/table.hxx | 2 +- sc/inc/validat.hxx | 4 ++-- sc/qa/unit/subsequent_export_test.cxx | 6 ++++-- sc/qa/unit/subsequent_export_test4.cxx | 8 ++++---- sc/qa/unit/subsequent_filters_test3.cxx | 18 +++++++++++------- sc/qa/unit/ucalc.cxx | 4 ++-- sc/qa/unit/ucalc_formula.cxx | 13 ++++++------- sc/source/core/data/column3.cxx | 2 +- sc/source/core/data/documen3.cxx | 14 ++------------ sc/source/core/data/table3.cxx | 2 +- sc/source/core/data/validat.cxx | 10 +++++----- sc/source/ui/app/inputhdl.cxx | 5 +---- sc/source/ui/view/gridwin.cxx | 2 +- 15 files changed, 43 insertions(+), 51 deletions(-)
New commits: commit 639a1f39dd45a6ff71eec2c073a84a9f181e350f Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Thu Aug 1 15:53:29 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Aug 1 21:03:13 2024 +0200 optimise GetDataEntries a little instead of swapping variously between std::vector, std::set<ScTypedStrData> and ScTypedCaseStrSet, just use the last one, which is the one that we want. Note that this is a behaviour change, because even though most of the code carefully used case-sensitive comparison, the code in ScColumn::GetEntries used the default ScTypedStrData::operator< which is case-insensitive. I think that case-sensitive is what we really want. Change-Id: I097dac6f5b5b1caa1d3dd7000aee516e9923c6e8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171378 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 22e3ad1e284c..510533a711e5 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -605,7 +605,7 @@ public: void GetBackColorFilterEntries(SCROW nRow1, SCROW nRow2, ScFilterEntries& rFilterEntries ); - bool GetDataEntries( SCROW nRow, std::set<ScTypedStrData>& rStrings) const; + bool GetDataEntries( SCROW nRow, ScTypedCaseStrSet& rStrings) const; void UpdateInsertTabAbs(SCTAB nNewPos); bool TestTabRefAbs(SCTAB nTable) const; diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 44e5bb0b4a62..17d75b0b4240 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -2246,7 +2246,7 @@ public: ScFilterEntries& rFilterEntries ); void GetDataEntries( SCCOL nCol, SCROW nRow, SCTAB nTab, - std::vector<ScTypedStrData>& rStrings, bool bValidation = false ); + ScTypedCaseStrSet& rStrings, bool bValidation = false ); void GetFormulaEntries( ScTypedCaseStrSet& rStrings ); bool HasAutoFilter( SCCOL nCol, SCROW nRow, SCTAB nTab ); diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 7da55e4cb3ee..473aad3cba00 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -1031,7 +1031,7 @@ public: void GetFilterEntries(SCCOL nCol, SCROW nRow1, SCROW nRow2, ScFilterEntries& rFilterEntries, bool bFiltering = false); void GetFilteredFilterEntries(SCCOL nCol, SCROW nRow1, SCROW nRow2, const ScQueryParam& rParam, ScFilterEntries& rFilterEntries, bool bFiltering ); [[nodiscard]] - bool GetDataEntries(SCCOL nCol, SCROW nRow, std::set<ScTypedStrData>& rStrings); + bool GetDataEntries(SCCOL nCol, SCROW nRow, ScTypedCaseStrSet& rStrings); bool HasColHeader( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow ) const; bool HasRowHeader( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow ) const; diff --git a/sc/inc/validat.hxx b/sc/inc/validat.hxx index 4afd9e2ba8f2..68d48b7e98a7 100644 --- a/sc/inc/validat.hxx +++ b/sc/inc/validat.hxx @@ -126,7 +126,7 @@ public: @descr Fills the list only, if this is a list validation and IsShowList() is enabled. @param rStrings (out-param) The string list to fill with list validation entries. @return true = rStrings has been filled with at least one entry. */ - SC_DLLPUBLIC bool FillSelectionList(std::vector<ScTypedStrData>& rStrings, const ScAddress& rPos) const; + SC_DLLPUBLIC bool FillSelectionList(ScTypedCaseStrSet& rStrings, const ScAddress& rPos) const; // with string: during input, with cell: for detective / RC_FORCED bool IsDataValid( @@ -181,7 +181,7 @@ private: @param rMatch (out-param) the index of the first item that matched, -1 if nothing matched. @return true = Cell range found, rRange is valid, or an error entry stuffed into the list if pCell==NULL. */ bool GetSelectionFromFormula( - std::vector<ScTypedStrData>* pStrings, ScRefCellValue& rCell, const ScAddress& rPos, + ScTypedCaseStrSet* pStrings, ScRefCellValue& rCell, const ScAddress& rPos, const ScTokenArray& rTokArr, int& rMatch) const; /** Tests, if pCell is equal to what the passed token array represents. */ diff --git a/sc/qa/unit/subsequent_export_test.cxx b/sc/qa/unit/subsequent_export_test.cxx index dde63a313271..da7e5d5c19ca 100644 --- a/sc/qa/unit/subsequent_export_test.cxx +++ b/sc/qa/unit/subsequent_export_test.cxx @@ -336,10 +336,12 @@ CPPUNIT_TEST_FIXTURE(ScExportTest, testTdf99856_dataValidationTest) CPPUNIT_ASSERT(pData); // Excel can't open corrupt file if the list is longer than 255 characters - std::vector<ScTypedStrData> aList; + ScTypedCaseStrSet aList; pData->FillSelectionList(aList, ScAddress(0, 1, 1)); CPPUNIT_ASSERT_EQUAL(size_t(18), aList.size()); - CPPUNIT_ASSERT_EQUAL(u"18 Missis"_ustr, aList[17].GetString()); + auto it = aList.begin(); + std::advance(it, 17); + CPPUNIT_ASSERT_EQUAL(u"9 Mississippi"_ustr, it->GetString()); } CPPUNIT_TEST_FIXTURE(ScExportTest, testProtectionKeyODS_UTF16LErtlSHA1) diff --git a/sc/qa/unit/subsequent_export_test4.cxx b/sc/qa/unit/subsequent_export_test4.cxx index fbf31673ada3..3fef1f6dc203 100644 --- a/sc/qa/unit/subsequent_export_test4.cxx +++ b/sc/qa/unit/subsequent_export_test4.cxx @@ -201,7 +201,7 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, testTdf151484) const ScValidationData* pData = pDoc->GetValidationEntry(1); CPPUNIT_ASSERT(pData); - std::vector<ScTypedStrData> aList; + ScTypedCaseStrSet aList; pData->FillSelectionList(aList, ScAddress(0, 1, 0)); // Without the fix in place, this test would have failed with @@ -209,9 +209,9 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, testTdf151484) // - Actual : 1 // - Failed on filter: MS Excel 97 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), size_t(4), aList.size()); - for (size_t j = 0; j < 4; ++j) - CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), double(j + 1), - aList[j].GetValue()); + auto it = aList.begin(); + for (size_t j = 0; j < 4; ++j, ++it) + CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), double(j + 1), it->GetValue()); } } diff --git a/sc/qa/unit/subsequent_filters_test3.cxx b/sc/qa/unit/subsequent_filters_test3.cxx index 14b2e315112e..5d91a95b65ac 100644 --- a/sc/qa/unit/subsequent_filters_test3.cxx +++ b/sc/qa/unit/subsequent_filters_test3.cxx @@ -1531,11 +1531,12 @@ CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf104310) CPPUNIT_ASSERT(pData); // Make sure the list is correct. - std::vector<ScTypedStrData> aList; + ScTypedCaseStrSet aList; pData->FillSelectionList(aList, ScAddress(0, 1, 0)); CPPUNIT_ASSERT_EQUAL(size_t(5), aList.size()); - for (size_t i = 0; i < 5; ++i) - CPPUNIT_ASSERT_DOUBLES_EQUAL(double(i + 1), aList[i].GetValue(), 1e-8); + auto it = aList.begin(); + for (size_t i = 0; i < 5; ++i, ++it) + CPPUNIT_ASSERT_DOUBLES_EQUAL(double(i + 1), it->GetValue(), 1e-8); } // 2. Test x12ac extension @@ -1547,12 +1548,15 @@ CPPUNIT_TEST_FIXTURE(ScFiltersTest3, testTdf104310) CPPUNIT_ASSERT(pData); // Make sure the list is correct. - std::vector<ScTypedStrData> aList; + ScTypedCaseStrSet aList; pData->FillSelectionList(aList, ScAddress(0, 1, 0)); CPPUNIT_ASSERT_EQUAL(size_t(3), aList.size()); - CPPUNIT_ASSERT_EQUAL(u"1"_ustr, aList[0].GetString()); - CPPUNIT_ASSERT_EQUAL(u"2,3"_ustr, aList[1].GetString()); - CPPUNIT_ASSERT_EQUAL(u"4"_ustr, aList[2].GetString()); + auto it = aList.begin(); + CPPUNIT_ASSERT_EQUAL(u"1"_ustr, it->GetString()); + ++it; + CPPUNIT_ASSERT_EQUAL(u"4"_ustr, it->GetString()); + ++it; + CPPUNIT_ASSERT_EQUAL(u"2,3"_ustr, it->GetString()); } } diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 2d8bbf59d286..2efd2c9bc3a9 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -830,12 +830,12 @@ CPPUNIT_TEST_FIXTURE(Test, testDataEntries) m_pDoc->SetString(ScAddress(0,7,0), u"Charlie"_ustr); m_pDoc->SetString(ScAddress(0,10,0), u"Andy"_ustr); - std::vector<ScTypedStrData> aEntries; + ScTypedCaseStrSet aEntries; m_pDoc->GetDataEntries(0, 0, 0, aEntries); // Try at the very top. // Entries are supposed to be sorted in ascending order, and are all unique. CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aEntries.size()); - std::vector<ScTypedStrData>::const_iterator it = aEntries.begin(); + auto it = aEntries.begin(); CPPUNIT_ASSERT_EQUAL(u"Andy"_ustr, it->GetString()); ++it; CPPUNIT_ASSERT_EQUAL(u"Bruce"_ustr, it->GetString()); diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx index 1660ce5daba4..4d3ff42ac14c 100644 --- a/sc/qa/unit/ucalc_formula.cxx +++ b/sc/qa/unit/ucalc_formula.cxx @@ -4211,7 +4211,7 @@ CPPUNIT_TEST_FIXTURE(TestFormula, testFormulaRefUpdateValidity) { struct { - bool checkList( std::vector<ScTypedStrData>& rList ) + bool checkList( ScTypedCaseStrSet& rList ) { double aExpected[] = { 1.0, 2.0, 3.0 }; // must be sorted. size_t nCheckSize = SAL_N_ELEMENTS(aExpected); @@ -4222,14 +4222,13 @@ CPPUNIT_TEST_FIXTURE(TestFormula, testFormulaRefUpdateValidity) return false; } - std::sort(rList.begin(), rList.end(), ScTypedStrData::LessCaseSensitive()); - - for (size_t i = 0; i < nCheckSize; ++i) + auto it = rList.begin(); + for (size_t i = 0; i < nCheckSize; ++i, ++it) { - if (aExpected[i] != rList[i].GetValue()) + if (aExpected[i] != it->GetValue()) { cerr << "Incorrect value at position " << i - << ": expected=" << aExpected[i] << ", actual=" << rList[i].GetValue() << endl; + << ": expected=" << aExpected[i] << ", actual=" << it->GetValue() << endl; return false; } } @@ -4266,7 +4265,7 @@ CPPUNIT_TEST_FIXTURE(TestFormula, testFormulaRefUpdateValidity) CPPUNIT_ASSERT(pData); // Make sure the list is correct. - std::vector<ScTypedStrData> aList; + ScTypedCaseStrSet aList; pData->FillSelectionList(aList, ScAddress(0,1,0)); bool bGood = aCheck.checkList(aList); CPPUNIT_ASSERT_MESSAGE("Initial list is incorrect.", bGood); diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index 26fcd36de0ba..d8b70b38a99d 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -2902,7 +2902,7 @@ public: // GetDataEntries - Strings from continuous Section around nRow bool ScColumn::GetDataEntries( - SCROW nStartRow, std::set<ScTypedStrData>& rStrings) const + SCROW nStartRow, ScTypedCaseStrSet& rStrings) const { // Start at the specified row position, and collect all string values // going upward and downward directions in parallel. The start position diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx index 6007ecf6d78f..c59172b4fc39 100644 --- a/sc/source/core/data/documen3.cxx +++ b/sc/source/core/data/documen3.cxx @@ -1627,7 +1627,7 @@ void ScDocument::GetFilterEntriesArea( */ void ScDocument::GetDataEntries( SCCOL nCol, SCROW nRow, SCTAB nTab, - std::vector<ScTypedStrData>& rStrings, bool bValidation ) + ScTypedCaseStrSet& rStrings, bool bValidation ) { if( bValidation ) { @@ -1639,24 +1639,14 @@ void ScDocument::GetDataEntries( { const ScValidationData* pData = GetValidationEntry( nValidation ); if( pData && pData->FillSelectionList( rStrings, ScAddress( nCol, nRow, nTab ) ) ) - { - if (pData->GetListType() == css::sheet::TableValidationVisibility::SORTEDASCENDING) - sortAndRemoveDuplicates(rStrings, true/*bCaseSens*/); - return; - } } } if (!HasTable(nTab)) return; - std::set<ScTypedStrData> aStrings; - if (maTabs[nTab]->GetDataEntries(nCol, nRow, aStrings)) - { - rStrings.insert(rStrings.end(), aStrings.begin(), aStrings.end()); - sortAndRemoveDuplicates(rStrings, true/*bCaseSens*/); - } + (void) maTabs[nTab]->GetDataEntries(nCol, nRow, rStrings); } /** diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx index 86c709f711c4..e0ce52d717b8 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -2935,7 +2935,7 @@ void ScTable::GetFilteredFilterEntries( } } -bool ScTable::GetDataEntries(SCCOL nCol, SCROW nRow, std::set<ScTypedStrData>& rStrings) +bool ScTable::GetDataEntries(SCCOL nCol, SCROW nRow, ScTypedCaseStrSet& rStrings) { if (!ValidCol(nCol) || nCol >= GetAllocatedColumnsCount()) return false; diff --git a/sc/source/core/data/validat.cxx b/sc/source/core/data/validat.cxx index 6a4a4aed064e..d467adcd215b 100644 --- a/sc/source/core/data/validat.cxx +++ b/sc/source/core/data/validat.cxx @@ -804,7 +804,7 @@ bool ScValidationData::HasSelectionList() const } bool ScValidationData::GetSelectionFromFormula( - std::vector<ScTypedStrData>* pStrings, ScRefCellValue& rCell, const ScAddress& rPos, + ScTypedCaseStrSet* pStrings, ScRefCellValue& rCell, const ScAddress& rPos, const ScTokenArray& rTokArr, int& rMatch) const { bool bOk = true; @@ -985,7 +985,7 @@ bool ScValidationData::GetSelectionFromFormula( if( pEntry ) { assert(pStrings); - pStrings->push_back(*pEntry); + pStrings->insert(*pEntry); n++; } } @@ -996,7 +996,7 @@ bool ScValidationData::GetSelectionFromFormula( return bOk || rCell.isEmpty(); } -bool ScValidationData::FillSelectionList(std::vector<ScTypedStrData>& rStrColl, const ScAddress& rPos) const +bool ScValidationData::FillSelectionList(ScTypedCaseStrSet& rStrColl, const ScAddress& rPos) const { bool bOk = false; @@ -1013,8 +1013,8 @@ bool ScValidationData::FillSelectionList(std::vector<ScTypedStrData>& rStrColl, double fValue; OUString aStr(pString); bool bIsValue = GetDocument()->GetFormatTable()->IsNumberFormat(aStr, nFormat, fValue); - rStrColl.emplace_back( - aStr, fValue, fValue, bIsValue ? ScTypedStrData::Value : ScTypedStrData::Standard); + rStrColl.insert( { + aStr, fValue, fValue, bIsValue ? ScTypedStrData::Value : ScTypedStrData::Standard } ); } bOk = aIt.Ok(); diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx index d9210251cc44..9968d161dd66 100644 --- a/sc/source/ui/app/inputhdl.cxx +++ b/sc/source/ui/app/inputhdl.cxx @@ -2068,11 +2068,8 @@ void ScInputHandler::GetColData() else pColumnData.reset( new ScTypedCaseStrSet ); - std::vector<ScTypedStrData> aEntries; rDoc.GetDataEntries( - aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), aEntries); - if (!aEntries.empty()) - pColumnData->insert(aEntries.begin(), aEntries.end()); + aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), *pColumnData); miAutoPosColumn = pColumnData->end(); } diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index 373122a12734..dbafb6f7bdc9 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -1536,7 +1536,7 @@ void ScGridWindow::LaunchDataSelectMenu(const SCCOL nCol, const SCROW nRow) const ScValidationData* pData = nIndex ? rDoc.GetValidationEntry(nIndex) : nullptr; bool bEmpty = false; - std::vector<ScTypedStrData> aStrings; // case sensitive + ScTypedCaseStrSet aStrings; // case sensitive // Fill List rDoc.GetDataEntries(nCol, nRow, nTab, aStrings, true /* bValidation */);