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()
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();
......
......@@ -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();
......
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