sw/source/uibase/shells/textsh1.cxx |   19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

New commits:
commit 2cf59dee9637dcb741806ce61e50b6be427dd7b8
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Jan 16 09:13:41 2023 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Jan 16 09:10:41 2023 +0000

    sw, UpdateBookmark: address some minor performance nits
    
    See
    
<https://gerrit.libreoffice.org/c/core/+/145413/2#message-6fda3c30e7b8cdab1137e2397a5f3f00b97d5acc>:
    
    - can start undo later, after making sure that we have a bookmark under
      the cursor
    
    - can look up the bookmark text later, after we managed to insert the
      marks (which may fail in some protected cursor position)
    
    Change-Id: I8ee183974fcc503a5c9a3964e86168888db13586
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145554
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/source/uibase/shells/textsh1.cxx 
b/sw/source/uibase/shells/textsh1.cxx
index 6956317af7bd..81a3f525bfc4 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -559,6 +559,14 @@ void UpdateBookmark(SfxRequest& rReq, SwWrtShell& rWrtSh)
         pBookmarks->GetValue() >>= aBookmark;
     }
 
+    IDocumentMarkAccess& rIDMA = *rWrtSh.GetDoc()->getIDocumentMarkAccess();
+    SwPosition& rCursor = *rWrtSh.GetCursor()->GetPoint();
+    auto pBookmark = 
dynamic_cast<sw::mark::Bookmark*>(rIDMA.getInnerBookmarkFor(rCursor));
+    if (!pBookmark || !pBookmark->GetName().startsWith(aBookmarkNamePrefix))
+    {
+        return;
+    }
+
     rWrtSh.GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSBOOKMARK, 
nullptr);
     rWrtSh.StartAction();
     comphelper::ScopeGuard g(
@@ -568,13 +576,6 @@ void UpdateBookmark(SfxRequest& rReq, SwWrtShell& rWrtSh)
             
rWrtSh.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSBOOKMARK, nullptr);
         });
 
-    IDocumentMarkAccess& rIDMA = *rWrtSh.GetDoc()->getIDocumentMarkAccess();
-    SwPosition& rCursor = *rWrtSh.GetCursor()->GetPoint();
-    auto pBookmark = 
dynamic_cast<sw::mark::Bookmark*>(rIDMA.getInnerBookmarkFor(rCursor));
-    if (!pBookmark || !pBookmark->GetName().startsWith(aBookmarkNamePrefix))
-    {
-        return;
-    }
 
     comphelper::SequenceAsHashMap aMap(aBookmark);
     if (aMap["Bookmark"].get<OUString>() != pBookmark->GetName())
@@ -582,8 +583,6 @@ void UpdateBookmark(SfxRequest& rReq, SwWrtShell& rWrtSh)
         rIDMA.renameMark(pBookmark, aMap["Bookmark"].get<OUString>());
     }
 
-    OUString aBookmarkText = aMap["BookmarkText"].get<OUString>();
-
     // Insert markers to remember where the paste positions are.
     SwPaM aMarkers(pBookmark->GetMarkEnd());
     IDocumentContentOperations& rIDCO = 
rWrtSh.GetDoc()->getIDocumentContentOperations();
@@ -595,6 +594,8 @@ void UpdateBookmark(SfxRequest& rReq, SwWrtShell& rWrtSh)
     SwPaM aPasteEnd(pBookmark->GetMarkEnd());
     aPasteEnd.Move(fnMoveForward, GoInContent);
 
+    OUString aBookmarkText = aMap["BookmarkText"].get<OUString>();
+
     // Paste HTML content.
     SwPaM* pCursorPos = rWrtSh.GetCursor();
     *pCursorPos = aPasteEnd;

Reply via email to