r24694 by jghali - Improve PageItemIterator performances by using std::vector instead of QStack
scribus-commit
scribus-commit at lists.scribus.net
Fri Aug 13 20:20:55 UTC 2021
Author: jghali
Date: Fri Aug 13 20:20:55 2021
New Revision: 24694
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24694
Log:
Improve PageItemIterator performances by using std::vector instead of QStack
Modified:
trunk/Scribus/scribus/pageitemiterator.cpp
trunk/Scribus/scribus/pageitemiterator.h
Modified: trunk/Scribus/scribus/pageitemiterator.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24694&path=/trunk/Scribus/scribus/pageitemiterator.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitemiterator.cpp (original)
+++ trunk/Scribus/scribus/pageitemiterator.cpp Fri Aug 13 20:20:55 2021
@@ -15,7 +15,7 @@
PageItemIterator::PageItemIterator(int options) :
m_options(options)
{
-
+ m_stateStack.reserve(16);
}
PageItemIterator::PageItemIterator(const QList<PageItem*>& itemList, int options) :
@@ -24,7 +24,8 @@
if (itemList.count() > 0)
{
State state = { itemList, 0 };
- m_stateStack.push(state);
+ m_stateStack.reserve(16);
+ m_stateStack.push_back(state);
m_current = next();
}
}
@@ -42,33 +43,20 @@
{
const ScPattern& pattern = it.value();
if (pattern.items.count() > 0)
- {
- State state = { pattern.items, 0 };
- m_stateStack.push(state);
- }
+ m_stateStack.emplace_back(pattern.items, 0);
}
}
if ((m_options & IterateInFrameItems) && (doc->FrameItems.count() > 0))
- {
- QList<PageItem*> frameItems = doc->FrameItems.values();
- State state = { frameItems, 0 };
- m_stateStack.push(state);
- }
+ m_stateStack.emplace_back(doc->FrameItems.values(), 0);
if ((m_options & IterateInMasterItems) && (doc->MasterItems.count() > 0))
- {
- State state = { doc->MasterItems, 0 };
- m_stateStack.push(state);
- }
+ m_stateStack.emplace_back(doc->MasterItems, 0);
if ((m_options & IterateInDocItems) && (doc->DocItems.count() > 0))
- {
- State state = { doc->DocItems, 0 };
- m_stateStack.push(state);
- }
+ m_stateStack.emplace_back(doc->DocItems, 0);
- if (m_stateStack.count() > 0)
+ if (m_stateStack.size() > 0)
m_current = next();
}
@@ -89,33 +77,20 @@
{
const ScPattern& pattern = it.value();
if (pattern.items.count() > 0)
- {
- State state = { pattern.items, 0 };
- m_stateStack.push(state);
- }
+ m_stateStack.emplace_back(pattern.items, 0);
}
}
if ((m_options & IterateInFrameItems) && (doc->FrameItems.count() > 0))
- {
- QList<PageItem*> frameItems = doc->FrameItems.values();
- State state = { frameItems, 0 };
- m_stateStack.push(state);
- }
+ m_stateStack.emplace_back(doc->FrameItems.values(), 0);
if ((m_options & IterateInMasterItems) && (doc->MasterItems.count() > 0))
- {
- State state = { doc->MasterItems, 0 };
- m_stateStack.push(state);
- }
+ m_stateStack.emplace_back(doc->MasterItems, 0);
if ((m_options & IterateInDocItems) && (doc->DocItems.count() > 0))
- {
- State state = { doc->DocItems, 0 };
- m_stateStack.push(state);
- }
+ m_stateStack.emplace_back(doc->DocItems, 0);
- if (m_stateStack.count() > 0)
+ if (m_stateStack.size() > 0)
m_current = next();
return m_current;
}
@@ -127,8 +102,7 @@
if (itemList.count() > 0)
{
- State state = { itemList, 0 };
- m_stateStack.push(state);
+ m_stateStack.emplace_back(itemList, 0);
m_current = next();
}
@@ -137,12 +111,12 @@
PageItem* PageItemIterator::next()
{
- while (m_stateStack.count() > 0)
+ while (m_stateStack.size() > 0)
{
- State& currentState = m_stateStack.top();
+ State& currentState = m_stateStack.back();
if (currentState.currentIndex >= currentState.itemList.count())
{
- m_stateStack.pop();
+ m_stateStack.pop_back();
continue;
}
@@ -161,10 +135,7 @@
m_current = groupItem;
currentState.currentIndex++;
if (groupItem->groupItemList.count() > 0)
- {
- State groupState = { groupItem->groupItemList, 0 };
- m_stateStack.push(groupState);
- }
+ m_stateStack.emplace_back(groupItem->groupItemList, 0);
break;
}
}
@@ -178,10 +149,7 @@
currentState.currentIndex++;
QList<PageItem*> cellItems = tableItem->getChildren();
if (cellItems.count() > 0)
- {
- State tableState = { cellItems, 0 };
- m_stateStack.push(tableState);
- }
+ m_stateStack.emplace_back(cellItems, 0);
break;
}
}
@@ -191,7 +159,7 @@
break;
}
- if (m_stateStack.isEmpty())
+ if (m_stateStack.empty())
m_current = nullptr;
return m_current;
}
Modified: trunk/Scribus/scribus/pageitemiterator.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24694&path=/trunk/Scribus/scribus/pageitemiterator.h
==============================================================================
--- trunk/Scribus/scribus/pageitemiterator.h (original)
+++ trunk/Scribus/scribus/pageitemiterator.h Fri Aug 13 20:20:55 2021
@@ -8,8 +8,8 @@
#ifndef PAGEITEMITERATOR_H
#define PAGEITEMITERATOR_H
+#include <vector>
#include <QList>
-#include <QStack>
#include "scribusapi.h"
@@ -52,13 +52,19 @@
protected:
struct State
{
+ State() {}
+ State(const QList<PageItem*> items, int startIndex)
+ {
+ itemList = items;
+ currentIndex = startIndex;
+ }
QList<PageItem*> itemList;
- int currentIndex;
+ int currentIndex { 0 };
};
int m_options { 0 };
PageItem* m_current { nullptr };
- QStack<State> m_stateStack;
+ std::vector<State> m_stateStack;
};
#endif // PAGEITEMITERATOR_H
More information about the scribus-commit
mailing list