QmlProfiler: Avoid indexOf and contains on list of strings

The iteration and comparison done by that takes significant time for
large traces.

Task-number: QTCREATORBUG-11823
Change-Id: I706b42f64ef0fd8b89229f51e52f0faaaf61d87a
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
This commit is contained in:
Ulf Hermann
2014-03-26 16:23:52 +01:00
parent cdec724ea5
commit 20e2d1eb7d

View File

@@ -119,6 +119,8 @@ void BasicTimelineModel::loadData()
d->prepare(); d->prepare();
QMap<QString, int> eventIdsByHash;
// collect events // collect events
const QVector<QmlProfilerDataModel::QmlEventData> eventList = simpleModel->getEvents(); const QVector<QmlProfilerDataModel::QmlEventData> eventList = simpleModel->getEvents();
foreach (const QmlProfilerDataModel::QmlEventData &event, eventList) { foreach (const QmlProfilerDataModel::QmlEventData &event, eventList) {
@@ -130,7 +132,9 @@ void BasicTimelineModel::loadData()
QString eventHash = QmlProfilerDataModel::getHashString(event); QString eventHash = QmlProfilerDataModel::getHashString(event);
// store in dictionary // store in dictionary
if (!d->eventHashes.contains(eventHash)) { int eventId;
QMap<QString, int>::const_iterator i = eventIdsByHash.constFind(eventHash);
if (i == eventIdsByHash.cend()) {
QmlRangeEventData rangeEventData = { QmlRangeEventData rangeEventData = {
event.displayName, event.displayName,
event.data.join(QLatin1String(" ")), event.data.join(QLatin1String(" ")),
@@ -139,11 +143,15 @@ void BasicTimelineModel::loadData()
lastEventId++ // event id lastEventId++ // event id
}; };
d->eventDict << rangeEventData; d->eventDict << rangeEventData;
eventId = d->eventHashes.size();
eventIdsByHash.insert(eventHash, eventId);
d->eventHashes << eventHash; d->eventHashes << eventHash;
} else {
eventId = i.value();
} }
// store starttime-based instance // store starttime-based instance
d->insert(event.startTime, event.duration, QmlRangeEventStartInstance(d->eventHashes.indexOf(eventHash))); d->insert(event.startTime, event.duration, QmlRangeEventStartInstance(eventId));
d->modelManager->modelProxyCountUpdated(d->modelId, d->count(), eventList.count() * 6); d->modelManager->modelProxyCountUpdated(d->modelId, d->count(), eventList.count() * 6);
} }