Commits

Bjoern Michaelsen  committed a209b27

itemsets: using ranges for changetracking in SwAttrSet

  • Participants
  • Parent commits 17c0c8f
  • Branches new_itemsets

Comments (0)

Files changed (1)

File sw/source/core/attr/swatrset.cxx

 namespace
 {
     // static for performance
-    // thus lcl_ChangeTracker is non reentrant
+    // thus ChangeTracker is non reentrant
     static ItemVector vChangeTrackerOldState;
-    class lcl_ChangeTracker
+    class ChangeTracker
     {
         public:
-            lcl_ChangeTracker(const SwAttrSet* const pAttrSet, const ItemVector* const pOldState)
-                : m_pAttrSet(pAttrSet)
+            ChangeTracker(const SwAttrSet* const pAttrSet, const ItemVector* const pOldState, const sal_uInt16 nMinWhich, const sal_uInt16 nMaxWhich)
+                : m_pAttrSet(pAttrSet), m_aMinEntry(nMinWhich), m_aMaxEntry(nMaxWhich)
             {
-                vChangeTrackerOldState.clear();
-                copy(pOldState->begin(), pOldState->end(), back_inserter(vChangeTrackerOldState));
+                ItemVector::const_iterator pBegin = lower_bound(pOldState->begin(), pOldState->end(), m_aMinEntry);
+                ItemVector::const_iterator pEnd = upper_bound(pBegin, pOldState->end(), m_aMaxEntry);
+                copy(pBegin, pEnd, back_inserter(vChangeTrackerOldState));
                 vChangeTrackerOldState.AddRefAll(m_pAttrSet->GetPool());
             };
 
-            ~lcl_ChangeTracker()
+            ~ChangeTracker()
             {
                 vChangeTrackerOldState.ReleaseRefAll(m_pAttrSet->GetPool());
                 vChangeTrackerOldState.clear();
                 SwAttrSet* pOld, SwAttrSet* pNew) const
             {
                 ItemVector::const_iterator pItemEntryOld = vChangeTrackerOldState.begin();
-                ItemVector::const_iterator pItemEntryNew = pNewState->begin();
                 ItemVector::const_iterator pOldEnd = vChangeTrackerOldState.end();
-                ItemVector::const_iterator pNewEnd = pNewState->end();
+                ItemVector::const_iterator pItemEntryNew = lower_bound(pNewState->begin(), pNewState->end(), m_aMinEntry);
+                ItemVector::const_iterator pNewEnd = upper_bound(pItemEntryNew, pNewState->end(), m_aMaxEntry);
                 while(pItemEntryOld != pOldEnd &&
                     pItemEntryNew != pNewEnd)
                 {
             };
         private:
             const SwAttrSet* const m_pAttrSet;
+            const ItemEntry m_aMinEntry;
+            const ItemEntry m_aMaxEntry;
 
             const SfxPoolItem& GetDefault(const USHORT nWhich) const
             {
 {
     if(!pOld)
         return (Put(rAttr) != NULL);
-    const lcl_ChangeTracker aChangeTracker(this, m_pItems.get());
+    const ChangeTracker aChangeTracker(this, m_pItems.get(), rAttr.Which(), rAttr.Which());
 	const bool nResult = Put(rAttr);
     aChangeTracker.MarkChangesForBroadcast(m_pItems.get(), pOld, pNew);
 	return nResult;
 {
     if(!pOld)
         return Put(rSet);
-    const lcl_ChangeTracker aChangeTracker(this, m_pItems.get());
+    const ChangeTracker aChangeTracker(this, m_pItems.get(), 0, SFX_WHICH_MAX);
 	const bool nResult = Put(rSet);
     aChangeTracker.MarkChangesForBroadcast(m_pItems.get(), pOld, pNew);
 	return nResult;
 {
     if(!pOld)
         return ClearItem(nWhich);
-    const lcl_ChangeTracker aChangeTracker(this, m_pItems.get());
+    const ChangeTracker aChangeTracker(this, m_pItems.get(), nWhich, nWhich);
 	const USHORT nResult = ClearItem(nWhich);
     aChangeTracker.MarkChangesForBroadcast(m_pItems.get(), pOld, pNew);
     return nResult;
             nRet = nRet + ClearItem(nWhich1);
         return nRet;
     }
-    const lcl_ChangeTracker aChangeTracker(this, m_pItems.get());
+    const ChangeTracker aChangeTracker(this, m_pItems.get(), nWhich1, nWhich2);
 	for(; nWhich1 <= nWhich2; ++nWhich1)
 		nRet = nRet + ClearItem(nWhich1);
     aChangeTracker.MarkChangesForBroadcast(m_pItems.get(), pOld, pNew);
         Intersect(rSet);
         return 0;
     }
-    const lcl_ChangeTracker aChangeTracker(this, m_pItems.get());
+    const ChangeTracker aChangeTracker(this, m_pItems.get(), 0, SFX_WHICH_MAX);
 	Intersect(rSet);
     aChangeTracker.MarkChangesForBroadcast(m_pItems.get(), pOld, pNew);
 	return pOld->Count(); //FIXME