From 20e2d1eb7d21ea36a654090544ac592854bd9f7e Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 26 Mar 2014 16:23:52 +0100 Subject: [PATCH] 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 --- .../qmlprofiler/qmlprofilertimelinemodelproxy.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.cpp b/src/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.cpp index 1488c5e47aa..cfcea9838e0 100644 --- a/src/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.cpp @@ -119,6 +119,8 @@ void BasicTimelineModel::loadData() d->prepare(); + QMap eventIdsByHash; + // collect events const QVector eventList = simpleModel->getEvents(); foreach (const QmlProfilerDataModel::QmlEventData &event, eventList) { @@ -130,7 +132,9 @@ void BasicTimelineModel::loadData() QString eventHash = QmlProfilerDataModel::getHashString(event); // store in dictionary - if (!d->eventHashes.contains(eventHash)) { + int eventId; + QMap::const_iterator i = eventIdsByHash.constFind(eventHash); + if (i == eventIdsByHash.cend()) { QmlRangeEventData rangeEventData = { event.displayName, event.data.join(QLatin1String(" ")), @@ -139,11 +143,15 @@ void BasicTimelineModel::loadData() lastEventId++ // event id }; d->eventDict << rangeEventData; + eventId = d->eventHashes.size(); + eventIdsByHash.insert(eventHash, eventId); d->eventHashes << eventHash; + } else { + eventId = i.value(); } // 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); }