include/svl/IndexedStyleSheets.hxx | 8 ++++---- svl/qa/unit/items/test_IndexedStyleSheets.cxx | 6 +++--- svl/source/items/IndexedStyleSheets.cxx | 16 ++++++---------- svl/source/items/style.cxx | 15 +++++---------- 4 files changed, 18 insertions(+), 27 deletions(-)
New commits: commit 6441778b61d1c6737947551e55d2c27e79260142 Author: Noel Grandin <[email protected]> AuthorDate: Fri Mar 8 15:56:11 2024 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Fri Mar 8 17:56:56 2024 +0100 tdf#158773 reduce size of IndexedStyleSheets we don't need to store SfxStyleFamily::All in the mStyleSheetsByFamily array, the call sites just iterate over the main vector for that case. Change-Id: I17fca2aa59e786d6dee13c884dedb9fde847b979 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164579 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/include/svl/IndexedStyleSheets.hxx b/include/svl/IndexedStyleSheets.hxx index 1a76604bd972..1734c7248e04 100644 --- a/include/svl/IndexedStyleSheets.hxx +++ b/include/svl/IndexedStyleSheets.hxx @@ -173,7 +173,7 @@ private: /** A map which stores the positions of style sheets by their name */ MapType mPositionsByName; - static constexpr size_t NUMBER_OF_FAMILIES = 7; + static constexpr size_t NUMBER_OF_FAMILIES = 6; std::array<std::vector<SfxStyleSheetBase*>, NUMBER_OF_FAMILIES> mStyleSheetsByFamily; }; diff --git a/svl/qa/unit/items/test_IndexedStyleSheets.cxx b/svl/qa/unit/items/test_IndexedStyleSheets.cxx index a94572de7fc9..314ce263ecd7 100644 --- a/svl/qa/unit/items/test_IndexedStyleSheets.cxx +++ b/svl/qa/unit/items/test_IndexedStyleSheets.cxx @@ -179,8 +179,8 @@ void IndexedStyleSheetsTest::PositionCanBeQueriedByFamily() const std::vector<SfxStyleSheetBase*>& v = iss.GetStyleSheetsByFamily(SfxStyleFamily::Char); CPPUNIT_ASSERT_EQUAL_MESSAGE("Separation by family works.", static_cast<size_t>(2), v.size()); - const std::vector<SfxStyleSheetBase*>& w = iss.GetStyleSheetsByFamily(SfxStyleFamily::All); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Wildcard works for family queries.", static_cast<size_t>(3), w.size()); + const std::vector<SfxStyleSheetBase*>& w = iss.GetStyleSheetsByFamily(SfxStyleFamily::Para); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wildcard works for family queries.", static_cast<size_t>(1), w.size()); } void IndexedStyleSheetsTest::OnlyOneStyleSheetIsReturnedWhenReturnFirstIsUsed() diff --git a/svl/source/items/IndexedStyleSheets.cxx b/svl/source/items/IndexedStyleSheets.cxx index 0c5f0f7cdafe..351e56425036 100644 --- a/svl/source/items/IndexedStyleSheets.cxx +++ b/svl/source/items/IndexedStyleSheets.cxx @@ -32,8 +32,6 @@ size_t family_to_index(SfxStyleFamily family) return 4; case SfxStyleFamily::Table: return 5; - case SfxStyleFamily::All: - return 6; default: break; } assert(false); // only for compiler warning. all cases are handled in the switch @@ -52,8 +50,6 @@ void IndexedStyleSheets::Register(SfxStyleSheetBase& style, sal_Int32 pos) mPositionsByName.insert(std::make_pair(style.GetName(), pos)); size_t position = family_to_index(style.GetFamily()); mStyleSheetsByFamily.at(position).push_back(&style); - size_t positionForFamilyAll = family_to_index(SfxStyleFamily::All); - mStyleSheetsByFamily.at(positionForFamilyAll).push_back(&style); } void commit 02f88f45e681beacf611f7c20f7903916b7e7374 Author: Noel Grandin <[email protected]> AuthorDate: Fri Mar 8 13:14:09 2024 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Fri Mar 8 17:56:46 2024 +0100 tdf#158773 reduce cost of stylesheet lookup we can store pointers styleSheetsByFamily and avoid having to access the vector Change-Id: I36b5df981b6e53d9aa4193de419fc6a44f0ed2da Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164573 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/include/svl/IndexedStyleSheets.hxx b/include/svl/IndexedStyleSheets.hxx index 3ca69f1c76d5..1a76604bd972 100644 --- a/include/svl/IndexedStyleSheets.hxx +++ b/include/svl/IndexedStyleSheets.hxx @@ -153,11 +153,11 @@ public: /** Get the positions of the style sheets which belong to a certain family. */ - const std::vector<sal_Int32>& GetStyleSheetPositionsByFamily(SfxStyleFamily) const; + const std::vector<SfxStyleSheetBase*>& GetStyleSheetsByFamily(SfxStyleFamily) const; private: /** Register the position of a styleName in the index */ - void Register(const SfxStyleSheetBase& style, sal_Int32 pos); + void Register(SfxStyleSheetBase& style, sal_Int32 pos); typedef std::vector<rtl::Reference<SfxStyleSheetBase>> VectorType; /** Vector with the stylesheets to allow for index-based access. @@ -175,7 +175,7 @@ private: static constexpr size_t NUMBER_OF_FAMILIES = 7; - std::array<std::vector<sal_Int32>, NUMBER_OF_FAMILIES> mStyleSheetPositionsByFamily; + std::array<std::vector<SfxStyleSheetBase*>, NUMBER_OF_FAMILIES> mStyleSheetsByFamily; }; } /* namespace svl */ diff --git a/svl/qa/unit/items/test_IndexedStyleSheets.cxx b/svl/qa/unit/items/test_IndexedStyleSheets.cxx index 6afaca629565..a94572de7fc9 100644 --- a/svl/qa/unit/items/test_IndexedStyleSheets.cxx +++ b/svl/qa/unit/items/test_IndexedStyleSheets.cxx @@ -176,10 +176,10 @@ void IndexedStyleSheetsTest::PositionCanBeQueriedByFamily() iss.AddStyleSheet(sheet2); iss.AddStyleSheet(sheet3); - const std::vector<sal_Int32>& v = iss.GetStyleSheetPositionsByFamily(SfxStyleFamily::Char); + const std::vector<SfxStyleSheetBase*>& v = iss.GetStyleSheetsByFamily(SfxStyleFamily::Char); CPPUNIT_ASSERT_EQUAL_MESSAGE("Separation by family works.", static_cast<size_t>(2), v.size()); - const std::vector<sal_Int32>& w = iss.GetStyleSheetPositionsByFamily(SfxStyleFamily::All); + const std::vector<SfxStyleSheetBase*>& w = iss.GetStyleSheetsByFamily(SfxStyleFamily::All); CPPUNIT_ASSERT_EQUAL_MESSAGE("Wildcard works for family queries.", static_cast<size_t>(3), w.size()); } diff --git a/svl/source/items/IndexedStyleSheets.cxx b/svl/source/items/IndexedStyleSheets.cxx index a9ca6908695d..0c5f0f7cdafe 100644 --- a/svl/source/items/IndexedStyleSheets.cxx +++ b/svl/source/items/IndexedStyleSheets.cxx @@ -47,13 +47,13 @@ IndexedStyleSheets::IndexedStyleSheets() { } -void IndexedStyleSheets::Register(const SfxStyleSheetBase& style, sal_Int32 pos) +void IndexedStyleSheets::Register(SfxStyleSheetBase& style, sal_Int32 pos) { mPositionsByName.insert(std::make_pair(style.GetName(), pos)); size_t position = family_to_index(style.GetFamily()); - mStyleSheetPositionsByFamily.at(position).push_back(pos); + mStyleSheetsByFamily.at(position).push_back(&style); size_t positionForFamilyAll = family_to_index(SfxStyleFamily::All); - mStyleSheetPositionsByFamily.at(positionForFamilyAll).push_back(pos); + mStyleSheetsByFamily.at(positionForFamilyAll).push_back(&style); } void @@ -61,7 +61,7 @@ IndexedStyleSheets::Reindex() { mPositionsByName.clear(); for (size_t i = 0; i < NUMBER_OF_FAMILIES; i++) { - mStyleSheetPositionsByFamily[i].clear(); + mStyleSheetsByFamily[i].clear(); } sal_Int32 i = 0; @@ -222,11 +222,11 @@ IndexedStyleSheets::FindPositionsByPredicate(StyleSheetPredicate& predicate) con return r; } -const std::vector<sal_Int32>& -IndexedStyleSheets::GetStyleSheetPositionsByFamily(SfxStyleFamily e) const +const std::vector<SfxStyleSheetBase*>& +IndexedStyleSheets::GetStyleSheetsByFamily(SfxStyleFamily e) const { size_t position = family_to_index(e); - return mStyleSheetPositionsByFamily.at(position); + return mStyleSheetsByFamily.at(position); } } /* namespace svl */ diff --git a/svl/source/items/style.cxx b/svl/source/items/style.cxx index 104cb793cc6d..0f208ad1cf26 100644 --- a/svl/source/items/style.cxx +++ b/svl/source/items/style.cxx @@ -415,7 +415,7 @@ sal_Int32 SfxStyleSheetIterator::Count() } else if(nMask == SfxStyleSearchBits::All) { - n = static_cast<sal_uInt16>(pBasePool->pImpl->mxIndexedStyleSheets->GetStyleSheetPositionsByFamily(nSearchFamily).size()); + n = static_cast<sal_uInt16>(pBasePool->pImpl->mxIndexedStyleSheets->GetStyleSheetsByFamily(nSearchFamily).size()); } else { @@ -435,11 +435,7 @@ SfxStyleSheetBase* SfxStyleSheetIterator::operator[](sal_Int32 nIdx) } else if(nMask == SfxStyleSearchBits::All) { - rtl::Reference< SfxStyleSheetBase > ref = - pBasePool->pImpl->mxIndexedStyleSheets->GetStyleSheetByPosition( - pBasePool->pImpl->mxIndexedStyleSheets->GetStyleSheetPositionsByFamily(nSearchFamily).at(nIdx)) - ; - retval = ref.get(); + retval = pBasePool->pImpl->mxIndexedStyleSheets->GetStyleSheetsByFamily(nSearchFamily).at(nIdx); mnCurrentPosition = nIdx; } else @@ -489,14 +485,13 @@ SfxStyleSheetBase* SfxStyleSheetIterator::Next() else if(nMask == SfxStyleSearchBits::All) { sal_Int32 newPosition = mnCurrentPosition + 1; - const std::vector<sal_Int32>& familyVector + const std::vector<SfxStyleSheetBase*>& familyVector = - pBasePool->pImpl->mxIndexedStyleSheets->GetStyleSheetPositionsByFamily(nSearchFamily); + pBasePool->pImpl->mxIndexedStyleSheets->GetStyleSheetsByFamily(nSearchFamily); if (static_cast<sal_Int32>(familyVector.size()) > newPosition) { mnCurrentPosition = newPosition; - sal_Int32 stylePosition = familyVector[newPosition]; - retval = pBasePool->pImpl->mxIndexedStyleSheets->GetStyleSheetByPosition(stylePosition); + retval = familyVector[newPosition]; } } else
