[Libreoffice-commits] core.git: Branch 'libreoffice-7-2' - sw/inc sw/source
Noel Grandin (via logerrit)
logerrit at kemper.freedesktop.org
Tue Jun 15 13:39:46 UTC 2021
sw/inc/docstyle.hxx | 24 +++++++++++++++++-------
sw/source/uibase/app/docstyle.cxx | 33 ++++++++++++++++-----------------
2 files changed, 33 insertions(+), 24 deletions(-)
New commits:
commit e3611f81ee35998e3b8382d3c0fab6d4993e4626
Author: Noel Grandin <noel at peralex.com>
AuthorDate: Tue Jun 15 11:44:12 2021 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Jun 15 15:39:09 2021 +0200
tdf#135316 docx open performance
don't translate back and forth between two representations in
SwPoolFormatList
Shaves 2% off load time.wq
Change-Id: I098c15b92d5bc89fe1631edaed6827931cde5895
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117235
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
(cherry picked from commit 9966345f4faebb447d353ce68cee5765863273a2)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117219
diff --git a/sw/inc/docstyle.hxx b/sw/inc/docstyle.hxx
index 520404389fe9..77925dd5f670 100644
--- a/sw/inc/docstyle.hxx
+++ b/sw/inc/docstyle.hxx
@@ -115,7 +115,7 @@ public:
/** Preset the members without physical access.
Used by StyleSheetPool. */
void PresetName(const OUString& rName) { aName = rName; }
- void PresetNameAndFamily(const OUString& rName);
+ void PresetNameAndFamily(char cFamily, const OUString& rName);
void PresetParent(const OUString& rName){ aParent = rName; }
void PresetFollow(const OUString& rName){ aFollow = rName; }
@@ -141,25 +141,35 @@ public:
virtual bool IsUsed() const override;
};
+namespace std {
+template<>
+struct hash<std::pair<char,OUString>>
+{
+ std::size_t operator()(std::pair<char,OUString> const & pair) const
+ { return static_cast<std::size_t>(pair.first) ^ std::size_t(pair.second.hashCode()); }
+};
+}
+
+
// Iterator for Pool.
class SwStyleSheetIterator : public SfxStyleSheetIterator, public SfxListener
{
// Local helper class.
class SwPoolFormatList
{
- std::vector<OUString> maImpl;
- typedef std::unordered_map<OUString, sal_uInt32> UniqueHash;
+ std::vector<std::pair<char, OUString>> maImpl;
+ typedef std::unordered_map<std::pair<char, OUString>, sal_uInt32> UniqueHash;
UniqueHash maUnique;
void rehash();
public:
SwPoolFormatList() {}
- void Append( char cChar, std::u16string_view rStr );
+ void Append( char cChar, const OUString& rStr );
void clear() { maImpl.clear(); maUnique.clear(); }
size_t size() { return maImpl.size(); }
bool empty() { return maImpl.empty(); }
- sal_uInt32 FindName(SfxStyleFamily eFam, std::u16string_view rName);
- void RemoveName(SfxStyleFamily eFam, std::u16string_view rName);
- const OUString &operator[](sal_uInt32 nIdx) { return maImpl[ nIdx ]; }
+ sal_uInt32 FindName(SfxStyleFamily eFam, const OUString& rName);
+ void RemoveName(SfxStyleFamily eFam, const OUString& rName);
+ const std::pair<char,OUString> &operator[](sal_uInt32 nIdx) { return maImpl[ nIdx ]; }
};
rtl::Reference< SwDocStyleSheet > mxIterSheet;
diff --git a/sw/source/uibase/app/docstyle.cxx b/sw/source/uibase/app/docstyle.cxx
index 99b44f47ae86..9b3f98e16a1f 100644
--- a/sw/source/uibase/app/docstyle.cxx
+++ b/sw/source/uibase/app/docstyle.cxx
@@ -370,7 +370,7 @@ static const SwBoxAutoFormat* lcl_FindCellStyle(SwDoc& rDoc, std::u16string_view
}
sal_uInt32 SwStyleSheetIterator::SwPoolFormatList::FindName(SfxStyleFamily eFam,
- std::u16string_view rName)
+ const OUString& rName)
{
if(!maImpl.empty())
{
@@ -402,9 +402,7 @@ sal_uInt32 SwStyleSheetIterator::SwPoolFormatList::FindName(SfxStyleFamily eFam,
cStyle = ' ';
break;
}
- const OUString sSrch = OUStringChar(cStyle) + rName;
-
- UniqueHash::const_iterator it = maUnique.find(sSrch);
+ UniqueHash::const_iterator it = maUnique.find(std::pair<char,OUString>{cStyle, rName});
if (it != maUnique.end())
{
sal_uInt32 nIdx = it->second;
@@ -425,7 +423,7 @@ void SwStyleSheetIterator::SwPoolFormatList::rehash()
}
void SwStyleSheetIterator::SwPoolFormatList::RemoveName(SfxStyleFamily eFam,
- std::u16string_view rName)
+ const OUString& rName)
{
sal_uInt32 nTmpPos = FindName( eFam, rName );
if( nTmpPos < maImpl.size() )
@@ -437,16 +435,14 @@ void SwStyleSheetIterator::SwPoolFormatList::RemoveName(SfxStyleFamily eFam,
}
// Add Strings to the list of templates
-void SwStyleSheetIterator::SwPoolFormatList::Append( char cChar, std::u16string_view rStr )
+void SwStyleSheetIterator::SwPoolFormatList::Append( char cChar, const OUString& rStr )
{
- const OUString aStr = OUStringChar(cChar) + rStr;
-
- UniqueHash::const_iterator it = maUnique.find(aStr);
+ UniqueHash::const_iterator it = maUnique.find(std::pair<char,OUString>{cChar, rStr});
if (it != maUnique.end())
return;
- maUnique[aStr] = static_cast<sal_uInt32>(maImpl.size());
- maImpl.push_back(aStr);
+ maUnique.emplace(std::pair<char,OUString>{cChar, rStr}, static_cast<sal_uInt32>(maImpl.size()));
+ maImpl.push_back(std::pair<char,OUString>{cChar, rStr});
}
// UI-sided implementation of StyleSheets
@@ -2199,9 +2195,9 @@ SwTableAutoFormat* SwDocStyleSheet::GetTableFormat()
// re-generate Name AND Family from String
// First() and Next() (see below) insert an identification letter at Pos.1
-void SwDocStyleSheet::PresetNameAndFamily(const OUString& rName)
+void SwDocStyleSheet::PresetNameAndFamily(char cFamily, const OUString& rName)
{
- switch( rName[0] )
+ switch( cFamily )
{
case cPARA: nFamily = SfxStyleFamily::Para; break;
case cFRAME: nFamily = SfxStyleFamily::Frame; break;
@@ -2210,7 +2206,7 @@ void SwDocStyleSheet::PresetNameAndFamily(const OUString& rName)
case cTABSTYLE: nFamily = SfxStyleFamily::Table; break;
default: nFamily = SfxStyleFamily::Char; break;
}
- aName = rName.copy(1);
+ aName = rName;
}
// Is the format physically present yet
@@ -2679,7 +2675,8 @@ SfxStyleSheetBase* SwStyleSheetIterator::operator[]( sal_Int32 nIdx )
// found
if( !m_bFirstCalled )
First();
- mxStyleSheet->PresetNameAndFamily( m_aLst[ nIdx ] );
+ auto const & rEntry = m_aLst[ nIdx ];
+ mxStyleSheet->PresetNameAndFamily( rEntry.first, rEntry.second );
mxStyleSheet->SetPhysical( false );
mxStyleSheet->FillStyleSheet( SwDocStyleSheet::FillOnlyName );
@@ -3104,7 +3101,8 @@ SfxStyleSheetBase* SwStyleSheetIterator::Next()
++m_nLastPos;
if(m_nLastPos < m_aLst.size())
{
- mxIterSheet->PresetNameAndFamily(m_aLst[m_nLastPos]);
+ auto const & rEntry = m_aLst[m_nLastPos];
+ mxIterSheet->PresetNameAndFamily(rEntry.first, rEntry.second);
mxIterSheet->SetPhysical( false );
mxIterSheet->SetMask( nMask );
if(mxIterSheet->pSet)
@@ -3127,7 +3125,8 @@ SfxStyleSheetBase* SwStyleSheetIterator::Find(const OUString& rName)
if( SAL_MAX_UINT32 != m_nLastPos )
{
// found
- mxStyleSheet->PresetNameAndFamily(m_aLst[m_nLastPos]);
+ auto const & rEntry = m_aLst[m_nLastPos];
+ mxStyleSheet->PresetNameAndFamily(rEntry.first, rEntry.second);
// new name is set, so determine its Data
mxStyleSheet->FillStyleSheet( SwDocStyleSheet::FillOnlyName );
if( !mxStyleSheet->IsPhysical() )
More information about the Libreoffice-commits
mailing list