diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2021-06-22 22:39:27 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-06-23 09:55:59 +0200 |
commit | 1feb59c3dd9e5f714ce894f8de31bbb6869c9f3b (patch) | |
tree | ce8f05e8457a1b60ed318b4147054ed030e0bf56 /sw | |
parent | bc4cea4943c9189b92f51aacf097549023398b2e (diff) |
optimised FindFormatByName for SwFrameFormats
by re-arranging the boost::multi_index key, we can re-use
that index to find all formats matching a name
Change-Id: I3b3b6ceb7137926be3981578a64052f47f279af0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117676
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/doc.hxx | 12 | ||||
-rw-r--r-- | sw/inc/docary.hxx | 4 | ||||
-rw-r--r-- | sw/inc/editsh.hxx | 6 | ||||
-rw-r--r-- | sw/inc/frameformats.hxx | 11 | ||||
-rw-r--r-- | sw/source/core/attr/format.cxx | 2 | ||||
-rw-r--r-- | sw/source/core/doc/docchart.cxx | 2 | ||||
-rw-r--r-- | sw/source/core/doc/docfmt.cxx | 22 | ||||
-rw-r--r-- | sw/source/core/docnode/ndtbl.cxx | 9 | ||||
-rw-r--r-- | sw/source/core/edit/edfmt.cxx | 4 | ||||
-rw-r--r-- | sw/source/core/edit/editsh.cxx | 2 |
10 files changed, 46 insertions, 28 deletions
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx index b5edfcf39566..f72c2b89cb0d 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -761,13 +761,13 @@ public: SwFrameFormat *MakeFrameFormat(const OUString &rFormatName, SwFrameFormat *pDerivedFrom, bool bBroadcast = false, bool bAuto = true); void DelFrameFormat( SwFrameFormat *pFormat, bool bBroadcast = false ); - SwFrameFormat* FindFrameFormatByName( std::u16string_view rName ) const; + SwFrameFormat* FindFrameFormatByName( const OUString& rName ) const; SwCharFormat *MakeCharFormat(const OUString &rFormatName, SwCharFormat *pDerivedFrom, bool bBroadcast = false ); void DelCharFormat(size_t nFormat, bool bBroadcast = false); void DelCharFormat(SwCharFormat const * pFormat, bool bBroadcast = false); - SwCharFormat* FindCharFormatByName( std::u16string_view rName ) const + SwCharFormat* FindCharFormatByName( const OUString& rName ) const { return mpCharFormatTable->FindFormatByName(rName); } // Formatcollections (styles) @@ -795,7 +795,7 @@ public: const bool bReset = true, const bool bResetListAttrs = false, SwRootFrame const* pLayout = nullptr); - SwTextFormatColl* FindTextFormatCollByName( std::u16string_view rName ) const + SwTextFormatColl* FindTextFormatCollByName( const OUString& rName ) const { return mpTextFormatCollTable->FindFormatByName(rName); } void ChkCondColls(); @@ -813,7 +813,7 @@ public: SwFrameFormat& GetTableFrameFormat(size_t nFormat, bool bUsed ) const; SwTableFormat* MakeTableFrameFormat(const OUString &rFormatName, SwFrameFormat *pDerivedFrom); void DelTableFrameFormat( SwTableFormat* pFormat ); - SwTableFormat* FindTableFormatByName( std::u16string_view rName, bool bAll = false ) const; + SwTableFormat* FindTableFormatByName( const OUString& rName, bool bAll = false ) const; /** Access to frames. Iterate over Flys - for Basic-Collections. */ @@ -1269,7 +1269,7 @@ public: const SwTable* pCpyTable, bool bCpyName = false, bool bCorrPos = false ); - void UnProtectCells( std::u16string_view rTableName ); + void UnProtectCells( const OUString& rTableName ); bool UnProtectCells( const SwSelBoxes& rBoxes ); void UnProtectTables( const SwPaM& rPam ); bool HasTableAnyProtection( const SwPosition* pPos, @@ -1286,7 +1286,7 @@ public: sal_uInt16 nMode = 0 ); // Make charts of given table update. - void UpdateCharts( std::u16string_view rName ) const; + void UpdateCharts( const OUString& rName ) const; // Update all charts, for that exists any table. void UpdateAllCharts() { DoUpdateAllCharts(); } diff --git a/sw/inc/docary.hxx b/sw/inc/docary.hxx index 09c0dc3636d8..9ce149d7de89 100644 --- a/sw/inc/docary.hxx +++ b/sw/inc/docary.hxx @@ -49,7 +49,7 @@ public: virtual ~SwFormatsBase(); // default linear search implementation, some subclasses will override with a more efficient search - virtual SwFormat* FindFormatByName(std::u16string_view rName) const; + virtual SwFormat* FindFormatByName(const OUString& rName) const; SwFormatsBase() = default; SwFormatsBase(SwFormatsBase const &) = default; @@ -170,7 +170,7 @@ public: } // Override return type to reduce casting - virtual Value FindFormatByName(std::u16string_view rName) const override + virtual Value FindFormatByName(const OUString& rName) const override { return static_cast<Value>(SwFormatsBase::FindFormatByName(rName)); } }; diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx index f2d8c5300535..ca2c2efcb0ab 100644 --- a/sw/inc/editsh.hxx +++ b/sw/inc/editsh.hxx @@ -290,7 +290,7 @@ public: SwCharFormat* GetCurCharFormat() const; void FillByEx(SwCharFormat*); SwCharFormat* MakeCharFormat( const OUString& rName ); - SwCharFormat* FindCharFormatByName( std::u16string_view rName ) const; + SwCharFormat* FindCharFormatByName( const OUString& rName ) const; /* FormatCollections (new) - Explaining the general naming pattern: * GetXXXCount() returns the count of xxx in the document. @@ -333,7 +333,7 @@ public: SwTextFormatColl *MakeTextFormatColl(const OUString &rFormatCollName, SwTextFormatColl *pDerivedFrom = nullptr); void FillByEx(SwTextFormatColl*); - SwTextFormatColl* FindTextFormatCollByName( std::u16string_view rName ) const; + SwTextFormatColl* FindTextFormatCollByName( const OUString& rName ) const; /// @return "Auto-Collection" with given Id. If it does not exist create it. SwTextFormatColl* GetTextCollFromPool( sal_uInt16 nId ); @@ -677,7 +677,7 @@ public: void SetChartName( const OUString &rName ); /// Update content of all charts for table with given name. - void UpdateCharts( std::u16string_view rName ); + void UpdateCharts( const OUString& rName ); OUString GetCurWord() const; diff --git a/sw/inc/frameformats.hxx b/sw/inc/frameformats.hxx index 491adf9d3f70..45c76f9f9ad2 100644 --- a/sw/inc/frameformats.hxx +++ b/sw/inc/frameformats.hxx @@ -30,8 +30,9 @@ // We don't allow duplicated object entries! struct type_name_key : boost::multi_index::composite_key< - SwFrameFormat*, boost::multi_index::const_mem_fun<SwFormat, sal_uInt16, &SwFormat::Which>, + SwFrameFormat*, boost::multi_index::const_mem_fun<SwFormat, const OUString&, &SwFormat::GetName>, + boost::multi_index::const_mem_fun<SwFormat, sal_uInt16, &SwFormat::Which>, boost::multi_index::identity<SwFrameFormat*> // the actual object pointer > { @@ -88,6 +89,9 @@ public: // Convenience function, which just uses type and name! // To look for the exact object use find. ByTypeAndName::const_iterator findSimilar(const value_type& x) const; + // search for formats by name + std::pair<ByTypeAndName::const_iterator, ByTypeAndName::const_iterator> + findRangeByName(const OUString& name) const; // So we can actually check for end() ByTypeAndName::const_iterator typeAndNameEnd() const { return m_TypeAndNameIndex.end(); } @@ -114,10 +118,7 @@ public: void newDefault(const_iterator const& position); // Override return type to reduce casting - virtual SwFrameFormat* FindFormatByName(std::u16string_view rName) const override - { - return static_cast<SwFrameFormat*>(SwFormatsBase::FindFormatByName(rName)); - } + virtual SwFrameFormat* FindFormatByName(const OUString& rName) const override; }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/attr/format.cxx b/sw/source/core/attr/format.cxx index 676adf89fcf7..b6fa7bb6b179 100644 --- a/sw/source/core/attr/format.cxx +++ b/sw/source/core/attr/format.cxx @@ -769,7 +769,7 @@ void SwFormat::RemoveAllUnos() SwFormatsBase::~SwFormatsBase() {} -SwFormat* SwFormatsBase::FindFormatByName( std::u16string_view rName ) const +SwFormat* SwFormatsBase::FindFormatByName( const OUString& rName ) const { SwFormat* pFnd = nullptr; for( size_t n = 0; n < GetFormatCount(); ++n ) diff --git a/sw/source/core/doc/docchart.cxx b/sw/source/core/doc/docchart.cxx index cfa3f153074b..693f16886468 100644 --- a/sw/source/core/doc/docchart.cxx +++ b/sw/source/core/doc/docchart.cxx @@ -117,7 +117,7 @@ void SwDoc::UpdateCharts_( const SwTable& rTable, SwViewShell const & rVSh ) con } } -void SwDoc::UpdateCharts( std::u16string_view rName ) const +void SwDoc::UpdateCharts( const OUString& rName ) const { SwTable* pTmpTable = SwTable::FindTable( FindTableFormatByName( rName ) ); if( pTmpTable ) diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx index c45e268c26fc..5dc94ff60e82 100644 --- a/sw/source/core/doc/docfmt.cxx +++ b/sw/source/core/doc/docfmt.cxx @@ -731,7 +731,7 @@ void SwDoc::DelTableFrameFormat( SwTableFormat *pFormat ) delete pFormat; } -SwFrameFormat* SwDoc::FindFrameFormatByName( std::u16string_view rName ) const +SwFrameFormat* SwDoc::FindFrameFormatByName( const OUString& rName ) const { return mpFrameFormatTable->FindFormatByName( rName ); } @@ -2065,14 +2065,14 @@ SwFrameFormats::~SwFrameFormats() SwFrameFormats::const_iterator SwFrameFormats::find( const value_type& x ) const { ByTypeAndName::iterator it = m_TypeAndNameIndex.find( - boost::make_tuple(x->Which(), x->GetName(), x) ); + boost::make_tuple(x->GetName(), x->Which(), x) ); return m_Array.project<0>( it ); } SwFrameFormats::ByTypeAndName::const_iterator SwFrameFormats::findByTypeAndName( sal_uInt16 type, const OUString& name ) const { - return m_TypeAndNameIndex.find( boost::make_tuple(type, name) ); + return m_TypeAndNameIndex.find( boost::make_tuple(name, type) ); } SwFrameFormats::ByTypeAndName::const_iterator @@ -2081,6 +2081,22 @@ SwFrameFormats::findSimilar( const value_type& x ) const return findByTypeAndName( x->Which(), x->GetName() ); } +std::pair<SwFrameFormats::ByTypeAndName::const_iterator, SwFrameFormats::ByTypeAndName::const_iterator> +SwFrameFormats::findRangeByName( const OUString& rName ) const +{ + auto it = m_TypeAndNameIndex.lower_bound( boost::make_tuple(rName, sal_uInt16(0)) ); + auto itEnd = m_TypeAndNameIndex.lower_bound( boost::make_tuple(rName, SAL_MAX_UINT16) ); + return { it, itEnd }; +} + +SwFrameFormat* SwFrameFormats::FindFormatByName( const OUString& rName ) const +{ + auto it = m_TypeAndNameIndex.lower_bound( boost::make_tuple(rName, sal_uInt16(0)) ); + if (it != m_TypeAndNameIndex.end() && (*it)->GetName() == rName) + return *it; + return nullptr; +} + void SwFrameFormats::DeleteAndDestroyAll( bool keepDefault ) { if ( empty() ) diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx index 654cae173fe4..2fb74d2734d7 100644 --- a/sw/source/core/docnode/ndtbl.cxx +++ b/sw/source/core/docnode/ndtbl.cxx @@ -3945,17 +3945,18 @@ OUString SwDoc::GetUniqueTableName() const return aName + OUString::number( ++nNum ); } -SwTableFormat* SwDoc::FindTableFormatByName( std::u16string_view rName, bool bAll ) const +SwTableFormat* SwDoc::FindTableFormatByName( const OUString& rName, bool bAll ) const { const SwFormat* pRet = nullptr; if( bAll ) pRet = mpTableFrameFormatTable->FindFormatByName( rName ); else { + auto [it, itEnd] = mpTableFrameFormatTable->findRangeByName(rName); // Only the ones set in the Doc - for( size_t n = 0; n < mpTableFrameFormatTable->size(); ++n ) + for( ; it != itEnd; ++it ) { - const SwFrameFormat* pFormat = (*mpTableFrameFormatTable)[ n ]; + const SwFrameFormat* pFormat = *it; if( !pFormat->IsDefault() && IsUsed( *pFormat ) && pFormat->GetName() == rName ) { @@ -4441,7 +4442,7 @@ bool SwDoc::UnProtectTableCells( SwTable& rTable ) return bChgd; } -void SwDoc::UnProtectCells( std::u16string_view rName ) +void SwDoc::UnProtectCells( const OUString& rName ) { SwTableFormat* pFormat = FindTableFormatByName( rName ); if( pFormat ) diff --git a/sw/source/core/edit/edfmt.cxx b/sw/source/core/edit/edfmt.cxx index 8f450077cde3..ec03360cdc8f 100644 --- a/sw/source/core/edit/edfmt.cxx +++ b/sw/source/core/edit/edfmt.cxx @@ -146,12 +146,12 @@ const SwFlyFrameFormat* SwEditShell::FindFlyByName( const OUString& rName ) cons return mxDoc->FindFlyByName(rName); } -SwCharFormat* SwEditShell::FindCharFormatByName( std::u16string_view rName ) const +SwCharFormat* SwEditShell::FindCharFormatByName( const OUString& rName ) const { return mxDoc->FindCharFormatByName( rName ); } -SwTextFormatColl* SwEditShell::FindTextFormatCollByName( std::u16string_view rName ) const +SwTextFormatColl* SwEditShell::FindTextFormatCollByName( const OUString& rName ) const { return mxDoc->FindTextFormatCollByName( rName ); } diff --git a/sw/source/core/edit/editsh.cxx b/sw/source/core/edit/editsh.cxx index eea6cd397b86..f945017da201 100644 --- a/sw/source/core/edit/editsh.cxx +++ b/sw/source/core/edit/editsh.cxx @@ -395,7 +395,7 @@ void SwEditShell::SetChartName( const OUString &rName ) pONd->SetChartTableName( rName ); } -void SwEditShell::UpdateCharts( std::u16string_view rName ) +void SwEditShell::UpdateCharts( const OUString& rName ) { GetDoc()->UpdateCharts( rName ); } |