svl/source/items/itemset.cxx |   15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

New commits:
commit 3c3270c3527ce5bb7653727bc7749e4d58ba64cc
Author:     Armin Le Grand (allotropia) <armin.le.grand.ext...@allotropia.de>
AuthorDate: Thu Feb 15 19:14:42 2024 +0100
Commit:     Armin Le Grand <armin.le.gr...@me.com>
CommitDate: Fri Feb 16 17:05:59 2024 +0100

    ITEM: Better test for DynamicDefaultItems
    
    Change-Id: Ie18f18655e4ee9ca70580b540678003a12b0465d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163458
    Tested-by: Jenkins
    Reviewed-by: Armin Le Grand <armin.le.gr...@me.com>

diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx
index 05ba5672a02c..56cde0aec56c 100644
--- a/svl/source/items/itemset.cxx
+++ b/svl/source/items/itemset.cxx
@@ -499,13 +499,6 @@ SfxPoolItem const* implCreateItemEntry(SfxItemPool& rPool, 
SfxPoolItem const* pS
         // static default Items can just be used without RefCounting
         return pSource;
 
-    if (pSource->isDynamicDefault()
-        && pSource->isSetItem()
-        && static_cast<const SfxSetItem*>(pSource)->GetItemSet().GetPool() == 
&rPool)
-        // only use without RefCounting when SfxSetItem and the Pool is 
correct.
-        // all other cases just clone (as before)
-        return pSource;
-
     if (0 == pSource->Which())
     {
         // There should be no Items with 0 == WhichID, but there are some
@@ -516,6 +509,14 @@ SfxPoolItem const* implCreateItemEntry(SfxItemPool& rPool, 
SfxPoolItem const* pS
         return pSource->Clone();
     }
 
+    if (pSource->isDynamicDefault() && 
rPool.GetPoolDefaultItem(pSource->Which()) == pSource)
+        // dynamic defaults are not allowed to 'leave' the Pool they are
+        // defined for. We can check by comparing the PoolDefault (the
+        // PoolDefaultItem) to pSource by ptr compare (instance). When
+        // same Item we can use without RefCount. Else it will be cloned
+        // below the standard way.
+        return pSource;
+
 #ifdef DBG_UTIL
     // remember WhichID due to being able to assert Clone() error(s)
     const sal_uInt16 nWhich(pSource->Which());

Reply via email to