[Libreoffice-commits] core.git: sc/inc sc/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Mon Feb 11 09:36:08 UTC 2019
sc/inc/conditio.hxx | 20 +++++++++++++++++++-
sc/source/core/data/conditio.cxx | 30 ++++++++++--------------------
2 files changed, 29 insertions(+), 21 deletions(-)
New commits:
commit 941df80853cb6ab729f713eeb75984ba6dfec4ab
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon Feb 11 09:38:17 2019 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon Feb 11 10:35:45 2019 +0100
ScConditionalFormatList, don't use linear search
we can use the nice new C++14 compare methods to do this properly
Change-Id: Ic2a8e46747c4a105d93d32b5f58a061a2e0d4e26
Reviewed-on: https://gerrit.libreoffice.org/67666
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/sc/inc/conditio.hxx b/sc/inc/conditio.hxx
index 36703a7d2017..ae1097078c15 100644
--- a/sc/inc/conditio.hxx
+++ b/sc/inc/conditio.hxx
@@ -595,12 +595,30 @@ public:
void CalcAll();
};
+struct CompareScConditionalFormat
+{
+ using is_transparent = void;
+ bool operator()(std::unique_ptr<ScConditionalFormat> const& lhs,
+ std::unique_ptr<ScConditionalFormat> const& rhs) const
+ {
+ return (*lhs) < (*rhs);
+ }
+ bool operator()(sal_uInt32 nKey, std::unique_ptr<ScConditionalFormat> const& rpFormat) const
+ {
+ return nKey < rpFormat->GetKey();
+ }
+ bool operator()(std::unique_ptr<ScConditionalFormat> const& rpFormat, sal_uInt32 nKey) const
+ {
+ return rpFormat->GetKey() < nKey;
+ }
+};
+
// List of all conditional formats in a sheet
class SC_DLLPUBLIC ScConditionalFormatList
{
private:
typedef std::set<std::unique_ptr<ScConditionalFormat>,
- comphelper::UniquePtrValueLess<ScConditionalFormat>> ConditionalFormatContainer;
+ CompareScConditionalFormat> ConditionalFormatContainer;
ConditionalFormatContainer m_ConditionalFormats;
void operator =(ScConditionalFormatList const &) = delete;
diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx
index 81160bae754d..c992bd6f3ec3 100644
--- a/sc/source/core/data/conditio.cxx
+++ b/sc/source/core/data/conditio.cxx
@@ -2047,10 +2047,8 @@ void ScConditionalFormatList::InsertNew( std::unique_ptr<ScConditionalFormat> pN
ScConditionalFormat* ScConditionalFormatList::GetFormat( sal_uInt32 nKey )
{
- //FIXME: Binary search
- iterator itr = std::find_if(begin(), end(),
- [&nKey](const std::unique_ptr<ScConditionalFormat>& rxFormat) { return rxFormat->GetKey() == nKey; });
- if (itr != end())
+ auto itr = m_ConditionalFormats.find(nKey);
+ if (itr != m_ConditionalFormats.end())
return itr->get();
SAL_WARN("sc", "ScConditionalFormatList: Entry not found");
@@ -2059,10 +2057,8 @@ ScConditionalFormat* ScConditionalFormatList::GetFormat( sal_uInt32 nKey )
const ScConditionalFormat* ScConditionalFormatList::GetFormat( sal_uInt32 nKey ) const
{
- //FIXME: Binary search
- const_iterator itr = std::find_if(begin(), end(),
- [&nKey](const std::unique_ptr<ScConditionalFormat>& rxFormat) { return rxFormat->GetKey() == nKey; });
- if (itr != end())
+ auto itr = m_ConditionalFormats.find(nKey);
+ if (itr != m_ConditionalFormats.end())
return itr->get();
SAL_WARN("sc", "ScConditionalFormatList: Entry not found");
@@ -2152,8 +2148,8 @@ bool ScConditionalFormatList::CheckAllEntries(const Link<ScConditionalFormat*,vo
bool bValid = true;
// need to check which must be deleted
- iterator itr = begin();
- while(itr != end())
+ iterator itr = m_ConditionalFormats.begin();
+ while(itr != m_ConditionalFormats.end())
{
if ((*itr)->GetRange().empty())
{
@@ -2245,8 +2241,7 @@ bool ScConditionalFormatList::empty() const
void ScConditionalFormatList::erase( sal_uLong nIndex )
{
- iterator itr = std::find_if(begin(), end(),
- [&nIndex](const std::unique_ptr<ScConditionalFormat>& rxFormat) { return rxFormat->GetKey() == nIndex; });
+ auto itr = m_ConditionalFormats.find(nIndex);
if (itr != end())
m_ConditionalFormats.erase(itr);
}
@@ -2274,14 +2269,9 @@ void ScConditionalFormatList::clear()
sal_uInt32 ScConditionalFormatList::getMaxKey() const
{
- sal_uInt32 nMax = 0;
- for (const auto& aEntry : m_ConditionalFormats)
- {
- if (aEntry->GetKey() > nMax)
- nMax = aEntry->GetKey();
- }
-
- return nMax;
+ if (m_ConditionalFormats.empty())
+ return 0;
+ return (*m_ConditionalFormats.rbegin())->GetKey();
}
void ScConditionalFormatList::CalcAll()
More information about the Libreoffice-commits
mailing list