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 <noel.grandin@collabora.co.uk>
diff --git a/include/svl/IndexedStyleSheets.hxx b/include/svl/IndexedStyleSheets.hxx
index 3ca69f1..1a76604 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 6afaca6..a94572d 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 a9ca690..0c5f0f7 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 104cb79..0f208ad 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