sw/inc/IDocumentMarkAccess.hxx | 23 ++++++++++++- sw/inc/IMark.hxx | 20 ----------- sw/source/core/crsr/crbm.cxx | 12 +----- sw/source/core/doc/docbm.cxx | 58 ++++++++++++++++++++++++++++++--- sw/source/core/inc/MarkManager.hxx | 3 + sw/source/core/unocore/unoportenum.cxx | 14 ++----- sw/source/filter/writer/writer.cxx | 10 +---- 7 files changed, 88 insertions(+), 52 deletions(-)
New commits: commit 8ce36e943f0e50970925b2dd77729ef6036b4a49 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Sun May 26 15:15:41 2019 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sun May 26 18:01:53 2019 +0200 move some searching inside IDocumentMarkAccess to make followup improvements easier Change-Id: I2b0ab30589bc19a3e6c80228ab037745c7781292 Reviewed-on: https://gerrit.libreoffice.org/72978 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/inc/IDocumentMarkAccess.hxx b/sw/inc/IDocumentMarkAccess.hxx index d7111112612f..19431c67a343 100644 --- a/sw/inc/IDocumentMarkAccess.hxx +++ b/sw/inc/IDocumentMarkAccess.hxx @@ -130,7 +130,7 @@ class IDocumentMarkAccess @returns false, if renaming failed (because the name is already in use) */ - virtual bool renameMark(::sw::mark::IMark* io_pMark, + virtual bool renameMark(::sw::mark::IMark* io_pMark, const OUString& rNewName) =0; /** Corrects marks (absolute) @@ -224,6 +224,13 @@ class IDocumentMarkAccess */ virtual const_iterator_t findMark(const OUString& rMark) const =0; + /** Find the first Mark that does not start before. + + @returns + an iterator pointing to the mark, or pointing to getAllMarksEnd() if nothing was found. + */ + virtual const_iterator_t findFirstMarkStartsBefore(const SwPosition& rPos) const =0; + // interface IBookmarks (BOOKMARK, CROSSREF_NUMITEM_BOOKMARK, CROSSREF_HEADING_BOOKMARK ) /** returns a STL-like random access iterator to the begin of the sequence the IBookmarks. @@ -248,6 +255,14 @@ class IDocumentMarkAccess */ virtual const_iterator_t findBookmark(const OUString& rMark) const =0; + /** Finds the first mark that is starting after. + + @returns + an iterator pointing to the mark, or pointing to getBookmarksEnd() if nothing was found. + */ + virtual const_iterator_t findFirstBookmarkStartsAfter(const SwPosition& rPos) const =0; + + // Fieldmarks virtual ::sw::mark::IFieldmark* getFieldmarkFor(const SwPosition& pos) const =0; virtual ::sw::mark::IFieldmark* getFieldmarkBefore(const SwPosition& pos) const =0; @@ -268,6 +283,12 @@ class IDocumentMarkAccess virtual sal_Int32 getAnnotationMarksCount() const = 0; virtual const_iterator_t findAnnotationMark( const OUString& rName ) const = 0; virtual sw::mark::IMark* getAnnotationMarkFor(const SwPosition& rPosition) const = 0; + /** Finds the first mark that is starting after. + + @returns + an iterator pointing to the mark, or pointing to getAnnotationMarksEnd() if nothing was found. + */ + virtual const_iterator_t findFirstAnnotationStartsAfter(const SwPosition& rPos) const =0; /** Returns the MarkType used to create the mark */ diff --git a/sw/inc/IMark.hxx b/sw/inc/IMark.hxx index a58ecff0e8c2..d4ac261ba5e0 100644 --- a/sw/inc/IMark.hxx +++ b/sw/inc/IMark.hxx @@ -135,26 +135,6 @@ namespace sw { namespace mark ICheckboxFieldmark &operator =(ICheckboxFieldmark const&) = delete; }; - // Apple llvm-g++ 4.2.1 with _GLIBCXX_DEBUG won't eat boost::bind for this - // Neither will MSVC 2008 with _DEBUG - struct CompareIMarkStartsAfter - { - bool operator()(SwPosition const& rPos, - std::shared_ptr<sw::mark::IMark> const& pMark) - { - return pMark->StartsAfter(rPos); - } - }; - - struct CompareIMarkStartsBefore - { - bool operator()(std::shared_ptr<sw::mark::IMark> const& pMark, - SwPosition const& rPos) - { - return pMark->StartsBefore(rPos); - } - }; - OUString ExpandFieldmark(IFieldmark* pBM); }} diff --git a/sw/source/core/crsr/crbm.cxx b/sw/source/core/crsr/crbm.cxx index a63c191d3b7f..5aed657911e7 100644 --- a/sw/source/core/crsr/crbm.cxx +++ b/sw/source/core/crsr/crbm.cxx @@ -204,11 +204,7 @@ bool SwCursorShell::GoNextBookmark() IDocumentMarkAccess* pMarkAccess = getIDocumentMarkAccess(); IDocumentMarkAccess::container_t vCandidates; remove_copy_if( - upper_bound( // finds the first that is starting after - pMarkAccess->getBookmarksBegin(), - pMarkAccess->getBookmarksEnd(), - *GetCursor()->GetPoint(), - sw::mark::CompareIMarkStartsAfter()), + pMarkAccess->findFirstBookmarkStartsAfter(*GetCursor()->GetPoint()), pMarkAccess->getBookmarksEnd(), back_inserter(vCandidates), &lcl_IsInvisibleBookmark); @@ -244,11 +240,7 @@ bool SwCursorShell::GoPrevBookmark() IDocumentMarkAccess::container_t vCandidates; remove_copy_if( pMarkAccess->getBookmarksBegin(), - upper_bound( - pMarkAccess->getBookmarksBegin(), - pMarkAccess->getBookmarksEnd(), - *GetCursor()->GetPoint(), - sw::mark::CompareIMarkStartsAfter()), + pMarkAccess->findFirstBookmarkStartsAfter(*GetCursor()->GetPoint()), back_inserter(vCandidates), &lcl_IsInvisibleBookmark); sort( diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx index 6b28d7a54e7e..5f856cf4de0c 100644 --- a/sw/source/core/doc/docbm.cxx +++ b/sw/source/core/doc/docbm.cxx @@ -159,13 +159,34 @@ namespace return std::make_unique<SwPosition>(rOtherPosition); } + struct CompareIMarkStartsBefore + { + bool operator()(std::shared_ptr<sw::mark::IMark> const& pMark, + SwPosition const& rPos) + { + return pMark->StartsBefore(rPos); + } + }; + + // Apple llvm-g++ 4.2.1 with _GLIBCXX_DEBUG won't eat boost::bind for this + // Neither will MSVC 2008 with _DEBUG + struct CompareIMarkStartsAfter + { + bool operator()(SwPosition const& rPos, + std::shared_ptr<sw::mark::IMark> const& pMark) + { + return pMark->StartsAfter(rPos); + } + }; + + IMark* lcl_getMarkAfter(const IDocumentMarkAccess::container_t& rMarks, const SwPosition& rPos) { IDocumentMarkAccess::const_iterator_t pMarkAfter = upper_bound( rMarks.begin(), rMarks.end(), rPos, - sw::mark::CompareIMarkStartsAfter()); + CompareIMarkStartsAfter()); if(pMarkAfter == rMarks.end()) return nullptr; return pMarkAfter->get(); }; @@ -179,7 +200,7 @@ namespace rMarks.begin(), rMarks.end(), rPos, - sw::mark::CompareIMarkStartsAfter()); + CompareIMarkStartsAfter()); vCandidates.reserve(pCandidatesEnd - rMarks.begin()); // only marks ending before are candidates remove_copy_if( @@ -264,7 +285,7 @@ namespace for(IDocumentMarkAccess::iterator_t ppCurrentMark = lower_bound( rMarks.begin(), rMarks.end(), rPos, - sw::mark::CompareIMarkStartsBefore()); + CompareIMarkStartsBefore()); ppCurrentMark != rMarks.end(); ++ppCurrentMark) { @@ -1022,7 +1043,7 @@ namespace sw { namespace mark m_vAllMarks.begin(), m_vAllMarks.end(), pMark->GetMarkStart(), - sw::mark::CompareIMarkStartsBefore()); + CompareIMarkStartsBefore()); for ( ; it != m_vAllMarks.end(); ++it) if (pMark->StartsBefore((*it)->GetMarkStart())) break; @@ -1061,6 +1082,16 @@ namespace sw { namespace mark return lcl_FindMarkByName(rName, m_vBookmarks.begin(), m_vBookmarks.end()); } + // find the first Mark that does not start before + IDocumentMarkAccess::const_iterator_t MarkManager::findFirstMarkStartsBefore(const SwPosition& rPos) const + { + return std::lower_bound( + m_vAllMarks.begin(), + m_vAllMarks.end(), + rPos, + CompareIMarkStartsBefore()); + } + IDocumentMarkAccess::const_iterator_t MarkManager::getAllMarksBegin() const { return m_vAllMarks.begin(); } @@ -1079,6 +1110,16 @@ namespace sw { namespace mark sal_Int32 MarkManager::getBookmarksCount() const { return m_vBookmarks.size(); } + // finds the first that is starting after + IDocumentMarkAccess::const_iterator_t MarkManager::findFirstBookmarkStartsAfter(const SwPosition& rPos) const + { + return std::upper_bound( + m_vBookmarks.begin(), + m_vBookmarks.end(), + rPos, + CompareIMarkStartsAfter()); + } + IFieldmark* MarkManager::getFieldmarkFor(const SwPosition& rPos) const { const_iterator_t pFieldmark = find_if( @@ -1245,6 +1286,15 @@ namespace sw { namespace mark return pAnnotationMark->get(); } + // finds the first that is starting after + IDocumentMarkAccess::const_iterator_t MarkManager::findFirstAnnotationStartsAfter(const SwPosition& rPos) const + { + return std::upper_bound( + m_vAnnotationMarks.begin(), + m_vAnnotationMarks.end(), + rPos, + CompareIMarkStartsAfter()); + } OUString MarkManager::getUniqueMarkName(const OUString& rName) const { diff --git a/sw/source/core/inc/MarkManager.hxx b/sw/source/core/inc/MarkManager.hxx index fd0d19bf174d..2e794656cf6f 100644 --- a/sw/source/core/inc/MarkManager.hxx +++ b/sw/source/core/inc/MarkManager.hxx @@ -74,12 +74,14 @@ namespace sw { virtual const_iterator_t getAllMarksEnd() const override; virtual sal_Int32 getAllMarksCount() const override; virtual const_iterator_t findMark(const OUString& rName) const override; + virtual const_iterator_t findFirstMarkStartsBefore(const SwPosition& rPos) const override; // bookmarks virtual const_iterator_t getBookmarksBegin() const override; virtual const_iterator_t getBookmarksEnd() const override; virtual sal_Int32 getBookmarksCount() const override; virtual const_iterator_t findBookmark(const OUString& rName) const override; + virtual const_iterator_t findFirstBookmarkStartsAfter(const SwPosition& rPos) const override; // Fieldmarks virtual ::sw::mark::IFieldmark* getFieldmarkFor(const SwPosition& rPos) const override; @@ -103,6 +105,7 @@ namespace sw { virtual sal_Int32 getAnnotationMarksCount() const override; virtual const_iterator_t findAnnotationMark( const OUString& rName ) const override; virtual sw::mark::IMark* getAnnotationMarkFor(const SwPosition& rPos) const override; + virtual const_iterator_t findFirstAnnotationStartsAfter(const SwPosition& rPos) const override; virtual void assureSortedMarkContainers() const override; diff --git a/sw/source/core/unocore/unoportenum.cxx b/sw/source/core/unocore/unoportenum.cxx index 8c4f1201ac19..3c3f7d1f9404 100644 --- a/sw/source/core/unocore/unoportenum.cxx +++ b/sw/source/core/unocore/unoportenum.cxx @@ -186,11 +186,8 @@ namespace // no need to consider marks starting after aEndOfPara SwPosition aEndOfPara(*rUnoCursor.GetPoint()); aEndOfPara.nContent = aEndOfPara.nNode.GetNode().GetTextNode()->Len(); - const IDocumentMarkAccess::const_iterator_t pCandidatesEnd = upper_bound( - pMarkAccess->getBookmarksBegin(), - pMarkAccess->getBookmarksEnd(), - aEndOfPara, - sw::mark::CompareIMarkStartsAfter()); // finds the first that starts after + const IDocumentMarkAccess::const_iterator_t pCandidatesEnd = + pMarkAccess->findFirstBookmarkStartsAfter(aEndOfPara); // search for all bookmarks that start or end in this paragraph for(IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getBookmarksBegin(); @@ -270,11 +267,8 @@ namespace // no need to consider annotation marks starting after aEndOfPara SwPosition aEndOfPara(*rUnoCursor.GetPoint()); aEndOfPara.nContent = aEndOfPara.nNode.GetNode().GetTextNode()->Len(); - const IDocumentMarkAccess::const_iterator_t pCandidatesEnd = upper_bound( - pMarkAccess->getAnnotationMarksBegin(), - pMarkAccess->getAnnotationMarksEnd(), - aEndOfPara, - sw::mark::CompareIMarkStartsAfter()); // finds the first that starts after + const IDocumentMarkAccess::const_iterator_t pCandidatesEnd = + pMarkAccess->findFirstAnnotationStartsAfter(aEndOfPara); // search for all annotation marks that have its start position in this paragraph const SwNodeIndex nOwnNode = rUnoCursor.GetPoint()->nNode; diff --git a/sw/source/filter/writer/writer.cxx b/sw/source/filter/writer/writer.cxx index c374d261ce65..aa5c9eab397c 100644 --- a/sw/source/filter/writer/writer.cxx +++ b/sw/source/filter/writer/writer.cxx @@ -183,13 +183,9 @@ bool Writer::CopyNextPam( SwPaM ** ppPam ) sal_Int32 Writer::FindPos_Bkmk(const SwPosition& rPos) const { const IDocumentMarkAccess* const pMarkAccess = m_pDoc->getIDocumentMarkAccess(); - const IDocumentMarkAccess::const_iterator_t ppBkmk = std::lower_bound( - pMarkAccess->getAllMarksBegin(), - pMarkAccess->getAllMarksEnd(), - rPos, - sw::mark::CompareIMarkStartsBefore()); // find the first Mark that does not start before - if(ppBkmk != pMarkAccess->getAllMarksEnd()) - return ppBkmk - pMarkAccess->getAllMarksBegin(); + const IDocumentMarkAccess::const_iterator_t ppBkmk = pMarkAccess->findFirstBookmarkStartsAfter(rPos); + if(ppBkmk != pMarkAccess->getBookmarksEnd()) + return ppBkmk - pMarkAccess->getBookmarksBegin(); return -1; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits