qlalr: remove uses of inefficient QLists

For QList<QLinkedList<T>::iterator>, mark the iterator Q_PRIMITIVE_TYPE.
This should be done in Qt itself, but would be binary incompatible.

For two other types that are used as values in QMultiMap, replaced
   foreach (x, map.values(y))
with
   auto range = map.equal_range(y);
   for (auto it = range.first; it != ramge.second; ++it)
       x = *it;
which doesn't require a temporary QList.

Change-Id: I9ddd15dd9b1d5bb3000833d14ed911451a272328
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
This commit is contained in:
Marc Mutz 2015-06-16 16:48:27 +02:00
parent 18597b2ae2
commit cf9d112d7a
2 changed files with 18 additions and 2 deletions

View File

@ -362,8 +362,10 @@ void Automaton::closure (StatePointer state)
if (_M_grammar->isNonTerminal (*item->dot))
{
foreach (const RulePointer &rule, _M_grammar->rule_map.values (*item->dot))
const auto range = qAsConst(_M_grammar->rule_map).equal_range(*item->dot);
for (auto it = range.first; it != range.second; ++it)
{
const RulePointer &rule = *it;
Item ii;
ii.rule = rule;
ii.dot = rule->rhs.begin ();
@ -701,8 +703,10 @@ void Automaton::buildLookaheads ()
{
for (ItemPointer item = p->closure.begin (); item != p->closure.end (); ++item)
{
foreach (const Lookback &lookback, lookbacks.values (item))
const auto range = qAsConst(lookbacks).equal_range(item);
for (auto it = range.first; it != range.second; ++it)
{
const Lookback &lookback = *it;
StatePointer q = lookback.state;
#ifndef QLALR_NO_DEBUG_LOOKAHEADS

View File

@ -134,21 +134,33 @@ public:
// names
typedef QLinkedList<QString>::iterator Name;
QT_BEGIN_NAMESPACE
Q_DECLARE_TYPEINFO(QLinkedList<QString>::iterator, Q_PRIMITIVE_TYPE);
QT_END_NAMESPACE
typedef QLinkedList<Name> NameList;
typedef OrderedSet<Name> NameSet;
// items
typedef QLinkedList<Item> ItemList;
typedef ItemList::iterator ItemPointer;
QT_BEGIN_NAMESPACE
Q_DECLARE_TYPEINFO(ItemList::iterator, Q_PRIMITIVE_TYPE);
QT_END_NAMESPACE
// rules
typedef QLinkedList<Rule> debug_infot;
typedef debug_infot::iterator RulePointer;
QT_BEGIN_NAMESPACE
Q_DECLARE_TYPEINFO(debug_infot::iterator, Q_PRIMITIVE_TYPE);
QT_END_NAMESPACE
typedef QMultiMap<Name, RulePointer> RuleMap;
// states
typedef QLinkedList<State> StateList;
typedef StateList::iterator StatePointer;
QT_BEGIN_NAMESPACE
Q_DECLARE_TYPEINFO(StateList::iterator, Q_PRIMITIVE_TYPE);
QT_END_NAMESPACE
// arrows
typedef QMap<Name, StatePointer> Bundle;