forked from qt-creator/qt-creator
Optimize TimelineModelPrivate::incrementStartIndices
Reduces the overhead of the function by a factor of ~500(depending on the event count) by having the Range(start) index to the RangeEnd so that we can only increment the RangeEnds that actually need to be incremented. Fixes: QTCREATORBUG-28162 Change-Id: I9daa711d0a1d960b232c5ed30564271daa68d1aa Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io> Reviewed-by: Janne Koskinen <janne.p.koskinen@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -444,7 +444,10 @@ int TimelineModel::insert(qint64 startTime, qint64 duration, int selectionId)
|
|||||||
int index = d->insertStart(TimelineModelPrivate::Range(startTime, duration, selectionId));
|
int index = d->insertStart(TimelineModelPrivate::Range(startTime, duration, selectionId));
|
||||||
if (index < d->ranges.size() - 1)
|
if (index < d->ranges.size() - 1)
|
||||||
d->incrementStartIndices(index);
|
d->incrementStartIndices(index);
|
||||||
d->insertEnd(TimelineModelPrivate::RangeEnd(index, startTime + duration));
|
int endIndex = d->insertEnd(TimelineModelPrivate::RangeEnd(index, startTime + duration));
|
||||||
|
d->setEndIndex(index, endIndex);
|
||||||
|
if (endIndex < d->endTimes.size() - 1)
|
||||||
|
d->incrementEndIndices(endIndex);
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -468,7 +471,10 @@ int TimelineModel::insertStart(qint64 startTime, int selectionId)
|
|||||||
void TimelineModel::insertEnd(int index, qint64 duration)
|
void TimelineModel::insertEnd(int index, qint64 duration)
|
||||||
{
|
{
|
||||||
d->ranges[index].duration = duration;
|
d->ranges[index].duration = duration;
|
||||||
d->insertEnd(TimelineModelPrivate::RangeEnd(index, d->ranges[index].start + duration));
|
int endIndex = d->insertEnd(TimelineModelPrivate::RangeEnd(index, d->ranges[index].start + duration));
|
||||||
|
d->setEndIndex(index, endIndex);
|
||||||
|
if (endIndex < d->endTimes.size() - 1)
|
||||||
|
d->incrementEndIndices(endIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TimelineModel::expanded() const
|
bool TimelineModel::expanded() const
|
||||||
|
@@ -52,13 +52,14 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Range {
|
struct Range {
|
||||||
Range() : start(-1), duration(-1), selectionId(-1), parent(-1) {}
|
Range() : start(-1), duration(-1), selectionId(-1), parent(-1), endIndex(-1) {}
|
||||||
Range(qint64 start, qint64 duration, int selectionId) :
|
Range(qint64 start, qint64 duration, int selectionId) :
|
||||||
start(start), duration(duration), selectionId(selectionId), parent(-1) {}
|
start(start), duration(duration), selectionId(selectionId), parent(-1), endIndex(-1) {}
|
||||||
qint64 start;
|
qint64 start;
|
||||||
qint64 duration;
|
qint64 duration;
|
||||||
int selectionId;
|
int selectionId;
|
||||||
int parent;
|
int parent;
|
||||||
|
int endIndex;
|
||||||
inline qint64 timestamp() const {return start;}
|
inline qint64 timestamp() const {return start;}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -77,11 +78,21 @@ public:
|
|||||||
|
|
||||||
void incrementStartIndices(int index)
|
void incrementStartIndices(int index)
|
||||||
{
|
{
|
||||||
for (RangeEnd &endTime : endTimes) {
|
for (index = index + 1; index < ranges.count(); index++) {
|
||||||
if (endTime.startIndex >= index)
|
if (ranges[index].endIndex >= 0)
|
||||||
++(endTime.startIndex);
|
endTimes[ranges[index].endIndex].startIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void incrementEndIndices(int index)
|
||||||
|
{
|
||||||
|
for (index = index + 1; index < endTimes.count(); index++)
|
||||||
|
ranges[endTimes[index].startIndex].endIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void setEndIndex(int index, int endIndex)
|
||||||
|
{
|
||||||
|
ranges[index].endIndex = endIndex;
|
||||||
|
}
|
||||||
|
|
||||||
inline int insertStart(const Range &start)
|
inline int insertStart(const Range &start)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user