QErrorMessage: replace inefficient QQueue with std::queue

QQueue is-a QList, so it inherits the trait that types larger than
a void* cause a heap-allocation when inserted, which is horribly
inefficient.

Use a std::queue instead, which, by default, is backed by std::deque.

Requires rewriting the API calls, since QQueue uses non-standard
function names.

Text and data size increase negligibly (23 and 8 bytes, respectively),
even though we're instantiating a completely new type (std::deque)
instead of QList<QPair<QString, QString>>, which is probably still
used, despite the inefficiency.

Change-Id: I9bb04a2ec32bb1b9fa2eb83780f0aaa26e872d49
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
bb10
Marc Mutz 2015-04-05 21:01:54 +02:00
parent 2d7128956f
commit 414dd4bf12
1 changed files with 8 additions and 6 deletions

View File

@ -47,9 +47,10 @@
#include "qpixmap.h"
#include "qmetaobject.h"
#include "qthread.h"
#include "qqueue.h"
#include "qset.h"
#include <queue>
#include <stdio.h>
#include <stdlib.h>
@ -68,7 +69,7 @@ public:
QCheckBox * again;
QTextEdit * errors;
QLabel * icon;
QQueue<QPair<QString, QString> > pending;
std::queue<QPair<QString, QString> > pending;
QSet<QString> doNotShow;
QSet<QString> doNotShowType;
QString currentMessage;
@ -305,10 +306,11 @@ QErrorMessage * QErrorMessage::qtHandler()
bool QErrorMessagePrivate::nextPending()
{
while (!pending.isEmpty()) {
QPair<QString,QString> pendingMessage = pending.dequeue();
while (!pending.empty()) {
const QPair<QString,QString> &pendingMessage = pending.front();
QString message = pendingMessage.first;
QString type = pendingMessage.second;
pending.pop();
if (!message.isEmpty() && ((type.isEmpty() && !doNotShow.contains(message)) || (!type.isEmpty() && !doNotShowType.contains(type)))) {
#ifndef QT_NO_TEXTHTMLPARSER
errors->setHtml(message);
@ -338,7 +340,7 @@ void QErrorMessage::showMessage(const QString &message)
Q_D(QErrorMessage);
if (d->doNotShow.contains(message))
return;
d->pending.enqueue(qMakePair(message,QString()));
d->pending.push(qMakePair(message,QString()));
if (!isVisible() && d->nextPending())
show();
}
@ -362,7 +364,7 @@ void QErrorMessage::showMessage(const QString &message, const QString &type)
Q_D(QErrorMessage);
if (d->doNotShow.contains(message) && d->doNotShowType.contains(type))
return;
d->pending.push_back(qMakePair(message,type));
d->pending.push(qMakePair(message,type));
if (!isVisible() && d->nextPending())
show();
}