[Libreoffice-commits] core.git: sc/source
Noel Grandin (via logerrit)
logerrit at kemper.freedesktop.org
Sat May 18 12:19:30 UTC 2019
sc/source/filter/xml/XMLStylesImportHelper.cxx | 45 ++++++++++---------------
sc/source/filter/xml/XMLStylesImportHelper.hxx | 32 +++++------------
2 files changed, 27 insertions(+), 50 deletions(-)
New commits:
commit ecf456d067346d49d7e2a366434477fa7de06d8a
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu May 16 13:10:03 2019 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sat May 18 14:18:22 2019 +0200
tdf#125254 Performance: A spreadsheet opens too slow, part3
Simplify the ScMyStyleRanges storage, does not need to be ref-counted.
This takes the load time from 40.5s to 39.5s.
Change-Id: I1b88ee1dd2cc4278b68aead846003c1cb858435b
Reviewed-on: https://gerrit.libreoffice.org/72514
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/sc/source/filter/xml/XMLStylesImportHelper.cxx b/sc/source/filter/xml/XMLStylesImportHelper.cxx
index 59d7476fbd03..a216817e51ff 100644
--- a/sc/source/filter/xml/XMLStylesImportHelper.cxx
+++ b/sc/source/filter/xml/XMLStylesImportHelper.cxx
@@ -238,29 +238,24 @@ void ScMyStylesImportHelper::ResetAttributes()
nCellType = 0;
}
-ScMyStylesSet::iterator ScMyStylesImportHelper::GetIterator(const boost::optional<OUString> & pStyleNameP)
+ScMyStylesMap::iterator ScMyStylesImportHelper::GetIterator(const OUString & rStyleName)
{
- ScMyStyle aStyle;
- if (pStyleNameP)
- aStyle.sStyleName = *pStyleNameP;
- else
- {
- OSL_FAIL("here is no stylename given");
- }
- auto itPair = aCellStyles.insert(aStyle);
- return itPair.first;
+ auto it = aCellStyles.find(rStyleName);
+ if (it == aCellStyles.end())
+ it = aCellStyles.emplace_hint(it, rStyleName, std::make_unique<ScMyStyleRanges>());
+ return it;
}
void ScMyStylesImportHelper::AddDefaultRange(const ScRange& rRange)
{
OSL_ENSURE(aRowDefaultStyle != aCellStyles.end(), "no row default style");
- if (aRowDefaultStyle->sStyleName.isEmpty())
+ if (aRowDefaultStyle->first.isEmpty())
{
SCCOL nStartCol(rRange.aStart.Col());
SCCOL nEndCol(rRange.aEnd.Col());
if (aColDefaultStyles.size() > sal::static_int_cast<sal_uInt32>(nStartCol))
{
- ScMyStylesSet::iterator aPrevItr(aColDefaultStyles[nStartCol]);
+ ScMyStylesMap::iterator aPrevItr(aColDefaultStyles[nStartCol]);
OSL_ENSURE(aColDefaultStyles.size() > sal::static_int_cast<sal_uInt32>(nEndCol), "to much columns");
for (SCCOL i = nStartCol + 1; (i <= nEndCol) && (i < sal::static_int_cast<SCCOL>(aColDefaultStyles.size())); ++i)
{
@@ -270,7 +265,7 @@ void ScMyStylesImportHelper::AddDefaultRange(const ScRange& rRange)
ScRange aRange(rRange);
aRange.aStart.SetCol(nStartCol);
aRange.aEnd.SetCol(i - 1);
- pPrevStyleName = aPrevItr->sStyleName;
+ pPrevStyleName = aPrevItr->first;
AddSingleRange(aRange);
nStartCol = i;
aPrevItr = aColDefaultStyles[i];
@@ -280,7 +275,7 @@ void ScMyStylesImportHelper::AddDefaultRange(const ScRange& rRange)
{
ScRange aRange(rRange);
aRange.aStart.SetCol(nStartCol);
- pPrevStyleName = aPrevItr->sStyleName;
+ pPrevStyleName = aPrevItr->first;
AddSingleRange(aRange);
}
else
@@ -295,21 +290,18 @@ void ScMyStylesImportHelper::AddDefaultRange(const ScRange& rRange)
}
else
{
- pPrevStyleName = aRowDefaultStyle->sStyleName;
+ pPrevStyleName = aRowDefaultStyle->first;
AddSingleRange(rRange);
}
}
void ScMyStylesImportHelper::AddSingleRange(const ScRange& rRange)
{
- ScMyStylesSet::iterator aItr(GetIterator(pPrevStyleName));
- if (aItr != aCellStyles.end())
- {
- if (nPrevCellType != util::NumberFormat::CURRENCY)
- aItr->xRanges->AddRange(rRange, nPrevCellType);
- else
- aItr->xRanges->AddCurrencyRange(rRange, pPrevCurrency);
- }
+ ScMyStylesMap::iterator aItr(GetIterator(*pPrevStyleName));
+ if (nPrevCellType != util::NumberFormat::CURRENCY)
+ aItr->second->AddRange(rRange, nPrevCellType);
+ else
+ aItr->second->AddCurrencyRange(rRange, pPrevCurrency);
}
void ScMyStylesImportHelper::AddRange()
@@ -324,8 +316,7 @@ void ScMyStylesImportHelper::AddRange()
void ScMyStylesImportHelper::AddColumnStyle(const OUString& sStyleName, const sal_Int32 nColumn, const sal_Int32 nRepeat)
{
OSL_ENSURE(static_cast<sal_uInt32>(nColumn) == aColDefaultStyles.size(), "some columns are absent");
- ScMyStylesSet::iterator aItr(GetIterator(sStyleName));
- OSL_ENSURE(aItr != aCellStyles.end(), "no column default style");
+ ScMyStylesMap::iterator aItr(GetIterator(sStyleName));
aColDefaultStyles.reserve(aColDefaultStyles.size() + nRepeat);
for (sal_Int32 i = 0; i < nRepeat; ++i)
aColDefaultStyles.push_back(aItr);
@@ -402,7 +393,7 @@ void ScMyStylesImportHelper::InsertCol(const sal_Int32 nCol, const sal_Int32 nTa
ScXMLImport::MutexGuard aGuard(rImport);
for (auto& rCellStyle : aCellStyles)
{
- rCellStyle.xRanges->InsertCol(nCol, nTab);
+ rCellStyle.second->InsertCol(nCol, nTab);
}
}
@@ -419,7 +410,7 @@ void ScMyStylesImportHelper::SetStylesToRanges()
{
for (auto& rCellStyle : aCellStyles)
{
- rCellStyle.xRanges->SetStylesToRanges(&rCellStyle.sStyleName, rImport);
+ rCellStyle.second->SetStylesToRanges(&rCellStyle.first, rImport);
}
aColDefaultStyles.clear();
aCellStyles.clear();
diff --git a/sc/source/filter/xml/XMLStylesImportHelper.hxx b/sc/source/filter/xml/XMLStylesImportHelper.hxx
index 005b23798519..5e3a9d1e67a7 100644
--- a/sc/source/filter/xml/XMLStylesImportHelper.hxx
+++ b/sc/source/filter/xml/XMLStylesImportHelper.hxx
@@ -27,6 +27,7 @@
#include <list>
#include <memory>
#include <set>
+#include <unordered_map>
#include <vector>
#include <boost/optional.hpp>
@@ -82,7 +83,7 @@ struct LessCurrencyStyle
typedef std::set<ScMyCurrencyStyle, LessCurrencyStyle> ScMyCurrencyStylesSet;
-class ScMyStyleRanges : public SvRefBase
+class ScMyStyleRanges
{
std::shared_ptr<ScSimpleRangeList> mpTextList;
std::shared_ptr<ScSimpleRangeList> mpNumberList;
@@ -98,36 +99,21 @@ class ScMyStyleRanges : public SvRefBase
const OUString* pCurrency, ScXMLImport& rImport);
public:
ScMyStyleRanges();
- virtual ~ScMyStyleRanges() override;
+ ~ScMyStyleRanges();
void AddRange(const ScRange& rRange, const sal_Int16 nType);
void AddCurrencyRange(const ScRange& rRange, const boost::optional<OUString> & pCurrency);
void InsertCol(const sal_Int32 nCol, const sal_Int32 nTab);
void SetStylesToRanges(const OUString* pStyleName, ScXMLImport& rImport);
};
-struct ScMyStyle
-{
- OUString sStyleName;
- tools::SvRef<ScMyStyleRanges> xRanges;
-
- ScMyStyle() : xRanges(new ScMyStyleRanges()) {}
-};
-
-struct LessStyle
-{
- bool operator() (const ScMyStyle& rValue1, const ScMyStyle& rValue2) const
- {
- return rValue1.sStyleName < rValue2.sStyleName;
- }
-};
-
-typedef std::set<ScMyStyle, LessStyle> ScMyStylesSet;
+/** map from style name to ScMyStyleRanges */
+typedef std::unordered_map<OUString, std::unique_ptr<ScMyStyleRanges>> ScMyStylesMap;
class ScMyStylesImportHelper
{
- ScMyStylesSet aCellStyles;
- std::vector<ScMyStylesSet::iterator> aColDefaultStyles;
- ScMyStylesSet::iterator aRowDefaultStyle;
+ ScMyStylesMap aCellStyles;
+ std::vector<ScMyStylesMap::iterator> aColDefaultStyles;
+ ScMyStylesMap::iterator aRowDefaultStyle;
ScXMLImport& rImport;
boost::optional<OUString>
pStyleName;
@@ -143,7 +129,7 @@ class ScMyStylesImportHelper
bool bPrevRangeAdded;
void ResetAttributes();
- ScMyStylesSet::iterator GetIterator(const boost::optional<OUString> & pStyleName);
+ ScMyStylesMap::iterator GetIterator(const OUString & rStyleName);
void AddDefaultRange(const ScRange& rRange);
void AddSingleRange(const ScRange& rRange);
void AddRange();
More information about the Libreoffice-commits
mailing list