From e91c79cb11b8c7b9df7846c12b5310eabbdb9ce8 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 7 Jul 2014 12:00:02 +0200 Subject: [PATCH] QmlProfiler: Allow ranges starting at the exact same time Previously, SortedTimelineModel could be confused by ranges starting at the exact same time if they were inserted in the wrong order. With this change the nesting calculation keeps track of that. Change-Id: Id296a54eed7e1ab421e94a296ec4e30adce185f2 Reviewed-by: Kai Koehne --- src/plugins/qmlprofiler/sortedtimelinemodel.h | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/plugins/qmlprofiler/sortedtimelinemodel.h b/src/plugins/qmlprofiler/sortedtimelinemodel.h index 564b0ab0616..9412a457469 100644 --- a/src/plugins/qmlprofiler/sortedtimelinemodel.h +++ b/src/plugins/qmlprofiler/sortedtimelinemodel.h @@ -143,18 +143,38 @@ public: QLinkedList parents; for (int range = 0; range != count(); ++range) { Range ¤t = ranges[range]; - for (QLinkedList::iterator parent = parents.begin(); parent != parents.end();) { - qint64 parentEnd = ranges[*parent].start + ranges[*parent].duration; + for (QLinkedList::iterator parentIt = parents.begin();;) { + Range &parent = ranges[*parentIt]; + qint64 parentEnd = parent.start + parent.duration; if (parentEnd < current.start) { - parent = parents.erase(parent); + if (parent.start == current.start) { + if (parent.parent == -1) { + parent.parent = range; + } else { + Range &ancestor = ranges[parent.parent]; + if (ancestor.start == current.start && + ancestor.duration < current.duration) + parent.parent = range; + } + // Just switch the old parent range for the new, larger one + *parentIt = range; + break; + } else { + parentIt = parents.erase(parentIt); + } } else if (parentEnd >= current.start + current.duration) { - current.parent = *parent; + // no need to insert + current.parent = *parentIt; break; } else { - ++parent; + ++parentIt; + } + + if (parentIt == parents.end()) { + parents.append(range); + break; } } - parents.append(range); } }