From dce7dbecb0135501eb8641c8f5ec8e98bddc808c Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 2 May 2019 19:56:29 +0200 Subject: qlalr: replace QLinkedList with std::list This is in preparation of deprecating QLinkedList. Most is straight-forward, except where operator+ was used on linked-list iterators. In one case, replaced this with std::next, in the other, with prefix increments, since the advancement was always equal to the loop control variable. Since advancing a linked-list iterator is a linear operation, this removes a source of quadratic complexity. Another obstacle was the overloaded op< set, which was in the Qt namespace while the iterator is from std and the payload, as before, was global. This breaks ADL, so move these operators to namespace std. This violates the standard, but the functions are tagged with our distinct types, so it shouldn't cause any trouble. Change-Id: Ifec0a927bfdabb002838cdf86fb8d23b32a38ff7 Reviewed-by: Giuseppe D'Angelo --- src/tools/qlalr/lalr.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/tools/qlalr/lalr.cpp') diff --git a/src/tools/qlalr/lalr.cpp b/src/tools/qlalr/lalr.cpp index 8af3b3c0db..b9a9cf264f 100644 --- a/src/tools/qlalr/lalr.cpp +++ b/src/tools/qlalr/lalr.cpp @@ -51,7 +51,9 @@ QTextStream &qout() static QTextStream result(stdout, QIODevice::WriteOnly); return result; } +QT_END_NAMESPACE +namespace std { bool operator < (Name a, Name b) { return *a < *b; @@ -66,7 +68,7 @@ bool operator < (StatePointer a, StatePointer b) { return &*a < &*b; } -QT_END_NAMESPACE +} bool Read::operator < (const Read &other) const { @@ -329,7 +331,7 @@ QPair Automaton::internState (const State &state) struct _Bucket { - QLinkedList items; + std::list items; void insert (ItemPointer item) { items.push_back (item); } @@ -338,8 +340,8 @@ struct _Bucket { State st (aut->_M_grammar); - for (QLinkedList::iterator item = items.begin (); item != items.end (); ++item) - st.insert ((*item)->next ()); + for (auto &item : items) + st.insert(item->next()); return st; } -- cgit v1.2.3