1. mst
  2. ooo340

Commits

Bjoern Michaelsen  committed 1bdfc79 Merge

itemsets: merging minibranches

  • Participants
  • Parent commits f526971, 4927f9a
  • Branches new_itemsets

Comments (0)

Files changed (1)

File svtools/source/items1/itemset.cxx

View file
             const bool m_bExists;
             const sal_uInt16 m_nWhich;
         public:
-            ItemPosition(
-                ItemVector* const pItems,
-                ItemVector::iterator pBegin,
-                ItemVector::iterator pEnd,
-                sal_uInt16 nWhich)
+            ItemPosition(ItemVector* const pItems, sal_uInt16 nWhich)
                 : m_pItems(pItems)
-                , m_pItemEntry(lower_bound(pBegin, pEnd, ItemEntry(nWhich)))
+                , m_pItemEntry(lower_bound(pItems->begin(), pItems->end(), ItemEntry(nWhich)))
                 , m_bExists(m_pItemEntry != m_pItems->end() && m_pItemEntry->GetWhich() == nWhich)
                 , m_nWhich(nWhich)
             {}
-            ItemPosition(ItemVector* const pItems, sal_uInt16 nWhich)
+            ItemPosition(
+                ItemVector* const pItems,
+                sal_uInt16 nWhich,
+                ItemVector::iterator pBegin,
+                ItemVector::iterator pEnd)
                 : m_pItems(pItems)
-                , m_pItemEntry(lower_bound(pItems->begin(), pItems->end(), ItemEntry(nWhich)))
+                , m_pItemEntry(lower_bound(pBegin, pEnd, ItemEntry(nWhich)))
                 , m_bExists(m_pItemEntry != m_pItems->end() && m_pItemEntry->GetWhich() == nWhich)
                 , m_nWhich(nWhich)
             {}
                 aItemEntry.SetItem(pNewItem, pPool);
                 return m_pItems->insert(m_pItemEntry, aItemEntry);
             }
-            void ReleaseAndErase(SfxItemPool* const pPool)
+            ItemVector::iterator ReleaseAndErase(SfxItemPool* const pPool)
             {
                 OSL_ENSURE(m_bExists, "<itemset.cxx:ItemPosition.ReleaseAndErase(..)>"
                     " - erasing an nonexisting position.");
                 m_pItemEntry->ReleaseItem(pPool);
                 m_pItems->erase(m_pItemEntry);
+                return m_pItemEntry;
             }
             ItemVector::iterator Reset(SfxPoolItem* const pNewItem, SfxItemPool* const pPool, const bool bSamePool = false)
             {
 bool SfxItemSet::Put(const SfxItemSet& rSet, bool bInvalidAsDefault)
 {
     bool isModified = false;
+    ItemVector::iterator pLastModification = m_pItems->begin();
     for(ItemVector::const_iterator pItemEntry = rSet.m_pItems->begin();
         pItemEntry != rSet.m_pItems->end();
         ++pItemEntry)
     {
-        if(IsInvalidItem(pItemEntry->GetItem()))
+        if(!lcl_InRange(m_vWhichRanges, pItemEntry->GetWhich()))
+            continue;
+        ItemPosition aItemPosition(m_pItems.get(), pItemEntry->GetWhich(), pLastModification, m_pItems->end());
+        SfxPoolItem* pSourceItem = const_cast<SfxPoolItem*>(pItemEntry->GetItem());
+        if(aItemPosition.DoesExist())
         {
-            if(bInvalidAsDefault)
-                isModified |= (ClearItem(pItemEntry->GetWhich()) != 0);
-            else
-                InvalidateItem(pItemEntry->GetWhich());
+            if(IsInvalidItem(pItemEntry->GetItem()))
+            {
+                if(bInvalidAsDefault)
+                {
+                    pLastModification = aItemPosition.ReleaseAndErase(m_pPool);
+                    isModified = true;
+                }
+                else
+                    aItemPosition.Reset(lcl_kInvalidItem, m_pPool);
+            }
+            else if(aItemPosition.GetItem() != pSourceItem
+                && *aItemPosition.GetItem() != *pSourceItem)
+            {
+                pLastModification = aItemPosition.Put(pSourceItem, m_pPool);
+                isModified = true;
+            }
         }
         else
-            isModified |= (Put(*pItemEntry->GetItem(), pItemEntry->GetWhich()) != 0);
+        {
+            pLastModification = aItemPosition.Create(pSourceItem, m_pPool);
+            isModified = true;
+        }
     }
     return isModified;
 }
 
 bool SfxItemSet::Set(const SfxItemSet& rSet, bool bDeep)
 {
-    bool bResult = false;
     ClearItem();
+    auto_ptr<vector<ItemEntry> > pSourceItems;
+    ItemVector::const_iterator pCandidatesBegin;
+    ItemVector::const_iterator pCandidatesEnd;
     if(bDeep)
     {
-        vector<ItemEntry> aSourceItems;
-        aSourceItems.reserve(64);
+        pSourceItems.reset(new vector<ItemEntry>());
+        pSourceItems->reserve(64);
         for(const SfxItemSet* pCurrent = &rSet;
             pCurrent;
             pCurrent = pCurrent->m_pParent)
         {
-            copy(pCurrent->m_pItems->begin(), pCurrent->m_pItems->end(), back_inserter(aSourceItems));
+            copy(pCurrent->m_pItems->begin(), pCurrent->m_pItems->end(), back_inserter(*pSourceItems));
         }
-        stable_sort(aSourceItems.begin(), aSourceItems.end());
-        vector<ItemEntry>::const_iterator pNewLast = unique(aSourceItems.begin(), aSourceItems.end());
-        for(ItemVector::iterator pItemEntry = aSourceItems.begin();
-            pItemEntry != pNewLast;
-            ++pItemEntry)
+        stable_sort(pSourceItems->begin(), pSourceItems->end());
+        pCandidatesBegin = pSourceItems->begin();
+        pCandidatesEnd = unique(pSourceItems->begin(), pSourceItems->end());
+    }
+    else
+    {
+        pCandidatesBegin = rSet.m_pItems->begin();
+        pCandidatesEnd = rSet.m_pItems->end();
+    }
+    bool isModified = false;
+    m_pItems->reserve(pCandidatesEnd-pCandidatesBegin);
+    for(ItemVector::const_iterator pItemEntry = pCandidatesBegin;
+        pItemEntry != pCandidatesEnd;
+        ++pItemEntry)
+    {
+        SfxPoolItem* const pItem = const_cast<SfxPoolItem*>(pItemEntry->GetItem());
+        if(!IsInvalidItem(pItem) && pItem->Which() && lcl_InRange(m_vWhichRanges, pItemEntry->GetWhich()))
         {
-            const SfxPoolItem* const pItem = pItemEntry->GetItem();
-            if(!IsInvalidItem(pItem) && pItem->Which())
-                bResult |= (Put(*pItem) != NULL);
+            ItemEntry aItemEntry(pItemEntry->GetWhich());
+            aItemEntry.SetItem(pItem, m_pPool);
+            m_pItems->push_back(aItemEntry);
+            isModified = true;
         }
     }
-    else
-        bResult = Put(rSet, false);
-    return bResult;
+    return isModified;
 }
 
 const SfxPoolItem* SfxItemSet::GetItem(sal_uInt16 nId, bool bSrchInParent, TypeId aItemType) const