Kaydet (Commit) ecf456d0 authored tarafından Noel Grandin's avatar Noel Grandin

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: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst bc11ba67
...@@ -238,29 +238,24 @@ void ScMyStylesImportHelper::ResetAttributes() ...@@ -238,29 +238,24 @@ void ScMyStylesImportHelper::ResetAttributes()
nCellType = 0; nCellType = 0;
} }
ScMyStylesSet::iterator ScMyStylesImportHelper::GetIterator(const boost::optional<OUString> & pStyleNameP) ScMyStylesMap::iterator ScMyStylesImportHelper::GetIterator(const OUString & rStyleName)
{ {
ScMyStyle aStyle; auto it = aCellStyles.find(rStyleName);
if (pStyleNameP) if (it == aCellStyles.end())
aStyle.sStyleName = *pStyleNameP; it = aCellStyles.emplace_hint(it, rStyleName, std::make_unique<ScMyStyleRanges>());
else return it;
{
OSL_FAIL("here is no stylename given");
}
auto itPair = aCellStyles.insert(aStyle);
return itPair.first;
} }
void ScMyStylesImportHelper::AddDefaultRange(const ScRange& rRange) void ScMyStylesImportHelper::AddDefaultRange(const ScRange& rRange)
{ {
OSL_ENSURE(aRowDefaultStyle != aCellStyles.end(), "no row default style"); OSL_ENSURE(aRowDefaultStyle != aCellStyles.end(), "no row default style");
if (aRowDefaultStyle->sStyleName.isEmpty()) if (aRowDefaultStyle->first.isEmpty())
{ {
SCCOL nStartCol(rRange.aStart.Col()); SCCOL nStartCol(rRange.aStart.Col());
SCCOL nEndCol(rRange.aEnd.Col()); SCCOL nEndCol(rRange.aEnd.Col());
if (aColDefaultStyles.size() > sal::static_int_cast<sal_uInt32>(nStartCol)) 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"); 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) 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) ...@@ -270,7 +265,7 @@ void ScMyStylesImportHelper::AddDefaultRange(const ScRange& rRange)
ScRange aRange(rRange); ScRange aRange(rRange);
aRange.aStart.SetCol(nStartCol); aRange.aStart.SetCol(nStartCol);
aRange.aEnd.SetCol(i - 1); aRange.aEnd.SetCol(i - 1);
pPrevStyleName = aPrevItr->sStyleName; pPrevStyleName = aPrevItr->first;
AddSingleRange(aRange); AddSingleRange(aRange);
nStartCol = i; nStartCol = i;
aPrevItr = aColDefaultStyles[i]; aPrevItr = aColDefaultStyles[i];
...@@ -280,7 +275,7 @@ void ScMyStylesImportHelper::AddDefaultRange(const ScRange& rRange) ...@@ -280,7 +275,7 @@ void ScMyStylesImportHelper::AddDefaultRange(const ScRange& rRange)
{ {
ScRange aRange(rRange); ScRange aRange(rRange);
aRange.aStart.SetCol(nStartCol); aRange.aStart.SetCol(nStartCol);
pPrevStyleName = aPrevItr->sStyleName; pPrevStyleName = aPrevItr->first;
AddSingleRange(aRange); AddSingleRange(aRange);
} }
else else
...@@ -295,21 +290,18 @@ void ScMyStylesImportHelper::AddDefaultRange(const ScRange& rRange) ...@@ -295,21 +290,18 @@ void ScMyStylesImportHelper::AddDefaultRange(const ScRange& rRange)
} }
else else
{ {
pPrevStyleName = aRowDefaultStyle->sStyleName; pPrevStyleName = aRowDefaultStyle->first;
AddSingleRange(rRange); AddSingleRange(rRange);
} }
} }
void ScMyStylesImportHelper::AddSingleRange(const ScRange& rRange) void ScMyStylesImportHelper::AddSingleRange(const ScRange& rRange)
{ {
ScMyStylesSet::iterator aItr(GetIterator(pPrevStyleName)); ScMyStylesMap::iterator aItr(GetIterator(*pPrevStyleName));
if (aItr != aCellStyles.end())
{
if (nPrevCellType != util::NumberFormat::CURRENCY) if (nPrevCellType != util::NumberFormat::CURRENCY)
aItr->xRanges->AddRange(rRange, nPrevCellType); aItr->second->AddRange(rRange, nPrevCellType);
else else
aItr->xRanges->AddCurrencyRange(rRange, pPrevCurrency); aItr->second->AddCurrencyRange(rRange, pPrevCurrency);
}
} }
void ScMyStylesImportHelper::AddRange() void ScMyStylesImportHelper::AddRange()
...@@ -324,8 +316,7 @@ void ScMyStylesImportHelper::AddRange() ...@@ -324,8 +316,7 @@ void ScMyStylesImportHelper::AddRange()
void ScMyStylesImportHelper::AddColumnStyle(const OUString& sStyleName, const sal_Int32 nColumn, const sal_Int32 nRepeat) 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"); OSL_ENSURE(static_cast<sal_uInt32>(nColumn) == aColDefaultStyles.size(), "some columns are absent");
ScMyStylesSet::iterator aItr(GetIterator(sStyleName)); ScMyStylesMap::iterator aItr(GetIterator(sStyleName));
OSL_ENSURE(aItr != aCellStyles.end(), "no column default style");
aColDefaultStyles.reserve(aColDefaultStyles.size() + nRepeat); aColDefaultStyles.reserve(aColDefaultStyles.size() + nRepeat);
for (sal_Int32 i = 0; i < nRepeat; ++i) for (sal_Int32 i = 0; i < nRepeat; ++i)
aColDefaultStyles.push_back(aItr); aColDefaultStyles.push_back(aItr);
...@@ -402,7 +393,7 @@ void ScMyStylesImportHelper::InsertCol(const sal_Int32 nCol, const sal_Int32 nTa ...@@ -402,7 +393,7 @@ void ScMyStylesImportHelper::InsertCol(const sal_Int32 nCol, const sal_Int32 nTa
ScXMLImport::MutexGuard aGuard(rImport); ScXMLImport::MutexGuard aGuard(rImport);
for (auto& rCellStyle : aCellStyles) for (auto& rCellStyle : aCellStyles)
{ {
rCellStyle.xRanges->InsertCol(nCol, nTab); rCellStyle.second->InsertCol(nCol, nTab);
} }
} }
...@@ -419,7 +410,7 @@ void ScMyStylesImportHelper::SetStylesToRanges() ...@@ -419,7 +410,7 @@ void ScMyStylesImportHelper::SetStylesToRanges()
{ {
for (auto& rCellStyle : aCellStyles) for (auto& rCellStyle : aCellStyles)
{ {
rCellStyle.xRanges->SetStylesToRanges(&rCellStyle.sStyleName, rImport); rCellStyle.second->SetStylesToRanges(&rCellStyle.first, rImport);
} }
aColDefaultStyles.clear(); aColDefaultStyles.clear();
aCellStyles.clear(); aCellStyles.clear();
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <list> #include <list>
#include <memory> #include <memory>
#include <set> #include <set>
#include <unordered_map>
#include <vector> #include <vector>
#include <boost/optional.hpp> #include <boost/optional.hpp>
...@@ -82,7 +83,7 @@ struct LessCurrencyStyle ...@@ -82,7 +83,7 @@ struct LessCurrencyStyle
typedef std::set<ScMyCurrencyStyle, LessCurrencyStyle> ScMyCurrencyStylesSet; typedef std::set<ScMyCurrencyStyle, LessCurrencyStyle> ScMyCurrencyStylesSet;
class ScMyStyleRanges : public SvRefBase class ScMyStyleRanges
{ {
std::shared_ptr<ScSimpleRangeList> mpTextList; std::shared_ptr<ScSimpleRangeList> mpTextList;
std::shared_ptr<ScSimpleRangeList> mpNumberList; std::shared_ptr<ScSimpleRangeList> mpNumberList;
...@@ -98,36 +99,21 @@ class ScMyStyleRanges : public SvRefBase ...@@ -98,36 +99,21 @@ class ScMyStyleRanges : public SvRefBase
const OUString* pCurrency, ScXMLImport& rImport); const OUString* pCurrency, ScXMLImport& rImport);
public: public:
ScMyStyleRanges(); ScMyStyleRanges();
virtual ~ScMyStyleRanges() override; ~ScMyStyleRanges();
void AddRange(const ScRange& rRange, const sal_Int16 nType); void AddRange(const ScRange& rRange, const sal_Int16 nType);
void AddCurrencyRange(const ScRange& rRange, const boost::optional<OUString> & pCurrency); void AddCurrencyRange(const ScRange& rRange, const boost::optional<OUString> & pCurrency);
void InsertCol(const sal_Int32 nCol, const sal_Int32 nTab); void InsertCol(const sal_Int32 nCol, const sal_Int32 nTab);
void SetStylesToRanges(const OUString* pStyleName, ScXMLImport& rImport); void SetStylesToRanges(const OUString* pStyleName, ScXMLImport& rImport);
}; };
struct ScMyStyle /** map from style name to ScMyStyleRanges */
{ typedef std::unordered_map<OUString, std::unique_ptr<ScMyStyleRanges>> ScMyStylesMap;
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;
class ScMyStylesImportHelper class ScMyStylesImportHelper
{ {
ScMyStylesSet aCellStyles; ScMyStylesMap aCellStyles;
std::vector<ScMyStylesSet::iterator> aColDefaultStyles; std::vector<ScMyStylesMap::iterator> aColDefaultStyles;
ScMyStylesSet::iterator aRowDefaultStyle; ScMyStylesMap::iterator aRowDefaultStyle;
ScXMLImport& rImport; ScXMLImport& rImport;
boost::optional<OUString> boost::optional<OUString>
pStyleName; pStyleName;
...@@ -143,7 +129,7 @@ class ScMyStylesImportHelper ...@@ -143,7 +129,7 @@ class ScMyStylesImportHelper
bool bPrevRangeAdded; bool bPrevRangeAdded;
void ResetAttributes(); void ResetAttributes();
ScMyStylesSet::iterator GetIterator(const boost::optional<OUString> & pStyleName); ScMyStylesMap::iterator GetIterator(const OUString & rStyleName);
void AddDefaultRange(const ScRange& rRange); void AddDefaultRange(const ScRange& rRange);
void AddSingleRange(const ScRange& rRange); void AddSingleRange(const ScRange& rRange);
void AddRange(); void AddRange();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment