summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-11-26 14:51:17 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-11-26 19:11:46 +0100
commit361fa01df3851fdc540144f54a17837c7f76103e (patch)
tree791e0943333df5fa293d953dbfdc6ade47f42f53
parentb62c43d1200e524369d9c7c2bd1dad3044efd672 (diff)
inline FindPositionsByName in a couple of places
it is no more complex, and it saves us the construction of an intermediate vector Change-Id: Ie92c2970c5b10805d7bcfc0cc2a74378f2cbda08 Reviewed-on: https://gerrit.libreoffice.org/64039 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--svl/source/items/IndexedStyleSheets.cxx30
1 files changed, 17 insertions, 13 deletions
diff --git a/svl/source/items/IndexedStyleSheets.cxx b/svl/source/items/IndexedStyleSheets.cxx
index 6b28873a05ba..c3b8ad6706c2 100644
--- a/svl/source/items/IndexedStyleSheets.cxx
+++ b/svl/source/items/IndexedStyleSheets.cxx
@@ -97,15 +97,16 @@ IndexedStyleSheets::AddStyleSheet(const rtl::Reference< SfxStyleSheetBase >& sty
bool
IndexedStyleSheets::RemoveStyleSheet(const rtl::Reference< SfxStyleSheetBase >& style)
{
- OUString styleName = style->GetName();
- std::vector<unsigned> positions = FindPositionsByName(styleName);
- auto it = std::find_if(positions.begin(), positions.end(),
- [&](const unsigned pos) { return mStyleSheets.at(pos) == style; });
-
- if (it != positions.end()) {
- mStyleSheets.erase(mStyleSheets.begin() + *it);
- Reindex();
- return true;
+ std::pair<MapType::const_iterator, MapType::const_iterator> range = mPositionsByName.equal_range(style->GetName());
+ for (MapType::const_iterator it = range.first; it != range.second; ++it)
+ {
+ unsigned pos = it->second;
+ if (mStyleSheets.at(pos) == style)
+ {
+ mStyleSheets.erase(mStyleSheets.begin() + pos);
+ Reindex();
+ return true;
+ }
}
return false;
}
@@ -199,10 +200,13 @@ IndexedStyleSheets::~IndexedStyleSheets()
bool
IndexedStyleSheets::HasStyleSheet(const rtl::Reference< SfxStyleSheetBase >& style) const
{
- OUString styleName = style->GetName();
- std::vector<unsigned> positions = FindPositionsByName(styleName);
- return std::any_of(positions.begin(), positions.end(),
- [&](const unsigned pos) { return mStyleSheets.at(pos) == style; });
+ std::pair<MapType::const_iterator, MapType::const_iterator> range = mPositionsByName.equal_range(style->GetName());
+ for (MapType::const_iterator it = range.first; it != range.second; ++it)
+ {
+ if (mStyleSheets.at(it->second) == style)
+ return true;
+ }
+ return false;
}
SfxStyleSheetBase*