diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2024-08-01 15:53:29 +0200 |
---|---|---|
committer | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-08-15 18:40:37 +0200 |
commit | d30701722bc13cdbe3c4ee405dec35d1816a9f32 (patch) | |
tree | 86cb25abd42eee0e2a099375943094a395bf674d /sc | |
parent | 4293485f7dcfe5a8c73df29f8777138808cc1b93 (diff) |
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.grandin@collabora.co.uk>
(cherry picked from commit 639a1f39dd45a6ff71eec2c073a84a9f181e350f)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171357
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/column.hxx | 2 | ||||
-rw-r--r-- | sc/inc/document.hxx | 2 | ||||
-rw-r--r-- | sc/inc/table.hxx | 2 | ||||
-rw-r--r-- | sc/inc/validat.hxx | 4 | ||||
-rw-r--r-- | sc/qa/unit/subsequent_export_test.cxx | 6 | ||||
-rw-r--r-- | sc/qa/unit/subsequent_export_test4.cxx | 8 | ||||
-rw-r--r-- | sc/qa/unit/subsequent_filters_test3.cxx | 18 | ||||
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 4 | ||||
-rw-r--r-- | sc/qa/unit/ucalc_formula.cxx | 13 | ||||
-rw-r--r-- | sc/source/core/data/column3.cxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/documen3.cxx | 14 | ||||
-rw-r--r-- | sc/source/core/data/table3.cxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/validat.cxx | 10 | ||||
-rw-r--r-- | sc/source/ui/app/inputhdl.cxx | 5 | ||||
-rw-r--r-- | sc/source/ui/view/gridwin.cxx | 2 |
15 files changed, 43 insertions, 51 deletions
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 47b2fd97d4ef..c079edfb96bf 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 a7f1c8322991..ea956dbbaa97 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -2215,7 +2215,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 a50e3c75491b..fef0247b4335 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -1035,7 +1035,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 af43e37cc123..72f277d2852f 100644 --- a/sc/inc/validat.hxx +++ b/sc/inc/validat.hxx @@ -128,7 +128,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. */ - bool FillSelectionList(std::vector<ScTypedStrData>& rStrings, const ScAddress& rPos) const; + bool FillSelectionList(ScTypedCaseStrSet& rStrings, const ScAddress& rPos) const; // with string: during input, with cell: for detective / RC_FORCED bool IsDataValid( @@ -183,7 +183,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 30600191d54a..0b4908fbe44c 100644 --- a/sc/qa/unit/subsequent_export_test.cxx +++ b/sc/qa/unit/subsequent_export_test.cxx @@ -335,10 +335,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(OUString("18 Missis"), aList[17].GetString()); + auto it = aList.begin(); + std::advance(it, 17); + CPPUNIT_ASSERT_EQUAL(OUString("9 Mississippi"), 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 95c7057aef2d..1130e1456fdd 100644 --- a/sc/qa/unit/subsequent_export_test4.cxx +++ b/sc/qa/unit/subsequent_export_test4.cxx @@ -198,7 +198,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 @@ -206,9 +206,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 cdde83913715..f70df0e23f02 100644 --- a/sc/qa/unit/subsequent_filters_test3.cxx +++ b/sc/qa/unit/subsequent_filters_test3.cxx @@ -1533,11 +1533,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 @@ -1549,12 +1550,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(OUString("1"), aList[0].GetString()); - CPPUNIT_ASSERT_EQUAL(OUString("2,3"), aList[1].GetString()); - CPPUNIT_ASSERT_EQUAL(OUString("4"), aList[2].GetString()); + auto it = aList.begin(); + CPPUNIT_ASSERT_EQUAL(OUString("1"), it->GetString()); + ++it; + CPPUNIT_ASSERT_EQUAL(OUString("4"), it->GetString()); + ++it; + CPPUNIT_ASSERT_EQUAL(OUString("2,3"), it->GetString()); } } diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 8ea8823277bb..3f9acb979163 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -657,12 +657,12 @@ CPPUNIT_TEST_FIXTURE(Test, testDataEntries) m_pDoc->SetString(ScAddress(0,7,0), "Charlie"); m_pDoc->SetString(ScAddress(0,10,0), "Andy"); - 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(OUString("Andy"), it->GetString()); ++it; CPPUNIT_ASSERT_EQUAL(OUString("Bruce"), it->GetString()); diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx index 153096d6a434..71574ce87151 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; } } @@ -4267,7 +4266,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 17e47452429d..d7302133642a 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -2905,7 +2905,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 8ae4ff6c4e87..aeb097fe61ee 100644 --- a/sc/source/core/data/documen3.cxx +++ b/sc/source/core/data/documen3.cxx @@ -1624,7 +1624,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 ) { @@ -1636,24 +1636,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 75b15b3c8c95..57a1a85ae084 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -2949,7 +2949,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 62f057539ccc..4239636ebb0e 100644 --- a/sc/source/core/data/validat.cxx +++ b/sc/source/core/data/validat.cxx @@ -806,7 +806,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; @@ -987,7 +987,7 @@ bool ScValidationData::GetSelectionFromFormula( if( pEntry ) { assert(pStrings); - pStrings->push_back(*pEntry); + pStrings->insert(*pEntry); n++; } } @@ -998,7 +998,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; @@ -1015,8 +1015,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 5b1d3cbdbced..4c5d1875fd31 100644 --- a/sc/source/ui/app/inputhdl.cxx +++ b/sc/source/ui/app/inputhdl.cxx @@ -2084,11 +2084,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 1db87192e9c2..4cf14941a547 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -1535,7 +1535,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 */); |