sw/source/core/unocore/unoportenum.cxx |   16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

New commits:
commit e4b66492cebe6cad3afa77e81db4d60eb9b7eba1
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Tue Jan 30 12:37:36 2024 +0600
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed Jan 31 17:52:54 2024 +0100

    Make sure to only dynamic_cast once
    
    Commit 3078020b07e41a6533ba71755d8cc8095bc3c3a7 (sw34bf04: #i109272#:
    SwXTextPortionEnumeration: fix CrossRefBookmark handling 2011-03-01)
    moved the dynamic_cast to the general case in lcl_FillBookmark. Later,
    commit 9b01059f6e2143c5b5b481f3d321309648fc7dd4 (SwXTextPortionEnumeration
    ctor: avoid dynamic_cast in the common case, 2014-10-28) split it into
    two: for bookmark start, and for bookmark end. Both will happen, when
    the bookmark is fully inside the node.
    
    This makes sure to only dynamic_cast once, and only when necessary.
    
    Change-Id: I3b88504b0cd21a644cf9933143312a4fb570b27a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162732
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162803

diff --git a/sw/source/core/unocore/unoportenum.cxx 
b/sw/source/core/unocore/unoportenum.cxx
index 4b50a72cf5ad..186b5c5b2354 100644
--- a/sw/source/core/unocore/unoportenum.cxx
+++ b/sw/source/core/unocore/unoportenum.cxx
@@ -133,12 +133,18 @@ namespace
     void lcl_FillBookmark(sw::mark::IMark* const pBkmk, const SwNode& 
rOwnNode, SwDoc& rDoc, SwXBookmarkPortion_ImplList& rBkmArr)
     {
         bool const hasOther = pBkmk->IsExpanded();
-
         const SwPosition& rStartPos = pBkmk->GetMarkStart();
-        if(rStartPos.GetNode() == rOwnNode)
+        const SwPosition& rEndPos = pBkmk->GetMarkEnd();
+        bool const bStartPosInNode = rStartPos.GetNode() == rOwnNode;
+        bool const bEndPosInNode = rEndPos.GetNode() == rOwnNode;
+        sw::mark::CrossRefBookmark* const pCrossRefMark
+            = !hasOther && (bStartPosInNode || bEndPosInNode)
+                  ? dynamic_cast<sw::mark::CrossRefBookmark*>(pBkmk)
+                  : nullptr;
+
+        if (bStartPosInNode)
         {
             // #i109272#: cross reference marks: need special handling!
-            ::sw::mark::CrossRefBookmark *const pCrossRefMark(dynamic_cast< 
::sw::mark::CrossRefBookmark*>(pBkmk));
             BkmType const nType = (hasOther || pCrossRefMark)
                 ? BkmType::Start : BkmType::StartEnd;
             rBkmArr.insert(std::make_shared<SwXBookmarkPortion_Impl>(
@@ -146,13 +152,11 @@ namespace
                         nType, rStartPos));
         }
 
-        const SwPosition& rEndPos = pBkmk->GetMarkEnd();
-        if(rEndPos.GetNode() != rOwnNode)
+        if (!bEndPosInNode)
             return;
 
         std::optional<SwPosition> oCrossRefEndPos;
         const SwPosition* pEndPos = nullptr;
-        ::sw::mark::CrossRefBookmark *const pCrossRefMark(dynamic_cast< 
::sw::mark::CrossRefBookmark*>(pBkmk));
         if(hasOther)
         {
             pEndPos = &rEndPos;

Reply via email to