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

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: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 72ba558e
......@@ -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
*/
......
......@@ -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);
}}
......
......@@ -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(
......
......@@ -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
{
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
}
......
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