sw/source/core/docnode/section.cxx |   90 +++++++++----------------------------
 1 file changed, 24 insertions(+), 66 deletions(-)

New commits:
commit 4ee947f221139bbfa209261fcf3c59f946f4e656
Author:     Bjoern Michaelsen <bjoern.michael...@libreoffice.org>
AuthorDate: Sat Nov 21 21:32:47 2020 +0100
Commit:     Bjoern Michaelsen <bjoern.michael...@libreoffice.org>
CommitDate: Sun Nov 22 09:45:51 2020 +0100

    Refactor SwSectionFormat::UpdateParent
    
    - This ancient piece of code managed to stack premature optimization on
      premature optimization all the while obfuscating the intend pretty
      well.
    - It also ultimately resulted in a pessimization, e.g. when a
      SwSectionFormat is found first, in which case GetSection() is called,
      which starts a new loop from the start.
    
    Change-Id: I8e33b3bc592740d7d144e7d4463eb62b27bc8fe4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106327
    Tested-by: Jenkins
    Reviewed-by: Bjoern Michaelsen <bjoern.michael...@libreoffice.org>

diff --git a/sw/source/core/docnode/section.cxx 
b/sw/source/core/docnode/section.cxx
index a59b9cffaa71..a3dad1262b23 100644
--- a/sw/source/core/docnode/section.cxx
+++ b/sw/source/core/docnode/section.cxx
@@ -929,79 +929,37 @@ bool SwSectionFormat::IsInNodesArr() const
 // Parent was changed
 void SwSectionFormat::UpdateParent()
 {
-    if( !HasWriterListeners() )
+    if(!HasWriterListeners())
         return;
 
-    SwSection* pSection = nullptr;
-    const SvxProtectItem* pProtect(nullptr);
+    const SwSection* pSection = GetSection();
+    const SvxProtectItem* pProtect = &GetProtect();
     // edit in readonly sections
-    const SwFormatEditInReadonly* pEditInReadonly = nullptr;
-    bool bIsHidden = false;
-
-    SwIterator<SwClient,SwSectionFormat> aIter(*this);
-    for(SwClient* pLast = aIter.First(); pLast; pLast = aIter.Next())
+    const SwFormatEditInReadonly* pEditInReadonly = &GetEditInReadonly();
+    bool bIsHidden = pSection->IsHidden();
+    if(GetRegisteredIn())
     {
-        if( dynamic_cast<const SwSectionFormat*>(pLast) !=  nullptr )
-        {
-            if( !pSection )
-            {
-                pSection = GetSection();
-                if( GetRegisteredIn() )
-                {
-                    const SwSection* pPS = GetParentSection();
-                    pProtect = &pPS->GetFormat()->GetProtect();
-                    // edit in readonly sections
-                    pEditInReadonly = &pPS->GetFormat()->GetEditInReadonly();
-                    bIsHidden = pPS->IsHiddenFlag();
-                }
-                else
-                {
-                    pProtect = &GetProtect();
-                    // edit in readonly sections
-                    pEditInReadonly = &GetEditInReadonly();
-                    bIsHidden = pSection->IsHidden();
-                }
-            }
-            if (!pProtect->IsContentProtected() !=
-                !pSection->IsProtectFlag())
-            {
-                
lcl_SwClientNotify(*static_cast<sw::BroadcastingModify*>(pLast), 
static_cast<SfxPoolItem const *>(pProtect));
-            }
+        const SwSection* pPS = GetParentSection();
+        pProtect = &pPS->GetFormat()->GetProtect();
+        pEditInReadonly = &pPS->GetFormat()->GetEditInReadonly();
+        bIsHidden = pPS->IsHiddenFlag();
+    }
+    SwIterator<SwSectionFormat,SwSectionFormat> aIter(*this);
+    for(SwSectionFormat* pLast = aIter.First(); pLast; pLast = aIter.Next())
+    {
+        if(!pProtect->IsContentProtected() != !pSection->IsProtectFlag())
+            lcl_SwClientNotify(*static_cast<sw::BroadcastingModify*>(pLast), 
static_cast<SfxPoolItem const *>(pProtect));
 
-            // edit in readonly sections
-            if (!pEditInReadonly->GetValue() !=
-                !pSection->IsEditInReadonlyFlag())
-            {
-                
lcl_SwClientNotify(*static_cast<sw::BroadcastingModify*>(pLast), 
static_cast<SfxPoolItem const *>(pEditInReadonly));
-            }
+        // edit in readonly sections
+        if(!pEditInReadonly->GetValue() != !pSection->IsEditInReadonlyFlag())
+            lcl_SwClientNotify(*static_cast<sw::BroadcastingModify*>(pLast), 
static_cast<SfxPoolItem const *>(pEditInReadonly));
 
-            if( bIsHidden == pSection->IsHiddenFlag() )
-            {
-                SwMsgPoolItem aMsgItem( static_cast<sal_uInt16>(bIsHidden
-                            ? RES_SECTION_HIDDEN
-                            : RES_SECTION_NOT_HIDDEN ) );
-                
lcl_SwClientNotify(*static_cast<sw::BroadcastingModify*>(pLast), &aMsgItem);
-            }
-        }
-        else if( !pSection &&
-                dynamic_cast<const SwSection*>(pLast) !=  nullptr )
+        if(bIsHidden == pSection->IsHiddenFlag())
         {
-            pSection = static_cast<SwSection*>(pLast);
-            if( GetRegisteredIn() )
-            {
-                const SwSection* pPS = GetParentSection();
-                pProtect = &pPS->GetFormat()->GetProtect();
-                // edit in readonly sections
-                pEditInReadonly = &pPS->GetFormat()->GetEditInReadonly();
-                bIsHidden = pPS->IsHiddenFlag();
-            }
-            else
-            {
-                pProtect = &GetProtect();
-                // edit in readonly sections
-                pEditInReadonly = &GetEditInReadonly();
-                bIsHidden = pSection->IsHidden();
-            }
+            SwMsgPoolItem aMsgItem( static_cast<sal_uInt16>(bIsHidden
+                        ? RES_SECTION_HIDDEN
+                        : RES_SECTION_NOT_HIDDEN ) );
+            lcl_SwClientNotify(*static_cast<sw::BroadcastingModify*>(pLast), 
&aMsgItem);
         }
     }
 }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to