Commits

Bjoern Michaelsen  committed 0f5dd0a

itemsets: using pointers for LegalWhichRanges because swapping them is cheaper

  • Participants
  • Parent commits 8e08444
  • Branches new_itemsets

Comments (0)

Files changed (1)

File svtools/source/items1/itemset.cxx

 #endif
     };
 
-    static void lcl_IntersectWhichRanges(vector<sal_uInt16> rRanges1, vector<sal_uInt16> rRanges2, vector<sal_uInt16>& o_rResult)
+    static void lcl_IntersectWhichRanges(const vector<sal_uInt16>* pRanges1, const vector<sal_uInt16>* pRanges2, vector<sal_uInt16>* o_pResult)
     {
-        o_rResult.clear();
-        vector<sal_uInt16>::const_iterator pCurrent1 = rRanges1.begin();
-        vector<sal_uInt16>::const_iterator pCurrent2 = rRanges2.begin();
+        o_pResult->clear();
+        vector<sal_uInt16>::const_iterator pCurrent1 = pRanges1->begin();
+        vector<sal_uInt16>::const_iterator pCurrent2 = pRanges2->begin();
         while(*pCurrent1 && *pCurrent2)
         {
             sal_uInt16 nLowerBound = max(*pCurrent1, *pCurrent2);
             sal_uInt16 nUpperBound = min(*(pCurrent1+1), *(pCurrent2+1));
             if(nLowerBound <= nUpperBound)
             {
-                o_rResult.push_back(nLowerBound);
-                o_rResult.push_back(nUpperBound);
+                o_pResult->push_back(nLowerBound);
+                o_pResult->push_back(nUpperBound);
             }
             if(*(pCurrent1+1) < *(pCurrent2+1))
                 pCurrent1 += 2;
             else
                 pCurrent2 += 2;
         }
-        o_rResult.push_back(0);
+        o_pResult->push_back(0);
     }
 
     static void lcl_FindRange(
         ClearItem();
         return false;
     }
+    bool bAllCandidatesInRange = false;
     auto_ptr<vector<ItemEntry> > pSourceItems;
     vector<ItemEntry>::iterator pCandidatesBegin;
     vector<ItemEntry>::iterator pCandidatesEnd;
     if(bDeep && rSet.m_pParent)
     {
-        vector<sal_uInt16> vLegalWhichRange;
-        vector<sal_uInt16> vOldLegalWhichRange;
+        bAllCandidatesInRange = true;
+        auto_ptr<vector<sal_uInt16> > pLegalWhichRange(new vector<sal_uInt16>());
+        auto_ptr<vector<sal_uInt16> > pOldLegalWhichRange(new vector<sal_uInt16>());
         auto_ptr<vector<ItemEntry> > pOldSourceItems(new vector<ItemEntry>());
         pSourceItems.reset(new vector<ItemEntry>());
         pSourceItems->reserve(128);
         pOldSourceItems->reserve(128);
-        vLegalWhichRange.reserve(32);
-        vOldLegalWhichRange.reserve(32);
-        copy(m_vWhichRanges.begin(), m_vWhichRanges.end(), back_inserter(vLegalWhichRange));
+        pLegalWhichRange->reserve(32);
+        pOldLegalWhichRange->reserve(32);
+        copy(m_vWhichRanges.begin(), m_vWhichRanges.end(), back_inserter(*pLegalWhichRange));
         for(const SfxItemSet* pCurrentSet = &rSet;
             pCurrentSet;
             pCurrentSet = pCurrentSet->m_pParent)
         {
-            swap(vLegalWhichRange, vOldLegalWhichRange);
-            lcl_IntersectWhichRanges(vOldLegalWhichRange, pCurrentSet->m_vWhichRanges, vLegalWhichRange);
-            if(vLegalWhichRange.size() < 3)
+            swap(pLegalWhichRange, pOldLegalWhichRange);
+            lcl_IntersectWhichRanges(pOldLegalWhichRange.get(), &pCurrentSet->m_vWhichRanges, pLegalWhichRange.get());
+            if(pLegalWhichRange->size() < 3)
                 break;
             ItemVector::iterator pLastRangeStart, pLastRangeEnd;
             lcl_FindRange(
-                vLegalWhichRange.begin(),
+                pLegalWhichRange->begin(),
                 pCurrentSet->m_pItems->begin(), pCurrentSet->m_pItems->end(),
                 pLastRangeStart, pLastRangeEnd);
-            for(vector<sal_uInt16>::const_iterator pCurrentRange = vLegalWhichRange.begin()+2;
+            for(vector<sal_uInt16>::const_iterator pCurrentRange = pLegalWhichRange->begin()+2;
                 *pCurrentRange && pLastRangeEnd != pCurrentSet->m_pItems->end();
                 pCurrentRange += 2)
             {
         ++pItemEntry)
     {
         SfxPoolItem* const pItem = const_cast<SfxPoolItem*>(pItemEntry->GetItem());
-        if(!IsInvalidItem(pItem) && pItem->Which() && lcl_InRange(m_vWhichRanges, pItemEntry->GetWhich()))
+        if(!IsInvalidItem(pItem) && pItem->Which()
+            && (bAllCandidatesInRange || lcl_InRange(m_vWhichRanges, pItemEntry->GetWhich())))
         {
             ItemEntry aItemEntry(pItemEntry->GetWhich());
             aItemEntry.SetItem(pItem, m_pPool);