renderer: use iterator rather than creating vectors

Creating vectors from the FrameHashCache was one of the slowest functions in the program, this should be significantly faster.
This commit is contained in:
itsmattkc
2021-07-11 16:47:12 -07:00
parent 9b0b3962fe
commit 8a58ee2bdb
9 changed files with 126 additions and 95 deletions
-71
View File
@@ -114,77 +114,6 @@ void FrameHashCache::ValidateFramesWithHash(const QByteArray &hash)
}
}
QList<rational> FrameHashCache::GetFramesWithHash(const QByteArray &hash)
{
QList<rational> times;
for (int64_t i=0; i<GetMapSize(); i++) {
if (time_hash_map_.at(i) == hash) {
times.append(ToTime(i));
}
}
return times;
}
QList<rational> FrameHashCache::TakeFramesWithHash(const QByteArray &hash)
{
TimeRangeList range_to_invalidate;
QList<rational> times;
for (int64_t i=0; i<GetMapSize(); i++) {
if (time_hash_map_.at(i) == hash) {
time_hash_map_[i].clear();
rational time = ToTime(i);
times.append(time);
range_to_invalidate.insert(TimeRange(time, time + timebase_));
}
}
foreach (const TimeRange& r, range_to_invalidate) {
// We apply a 0 job time because the graph hasn't changed to get here, so any renderer should
// be up to date already
Invalidate(r, 0);
}
return times;
}
QVector<rational> FrameHashCache::GetFrameListFromTimeRange(TimeRangeList range_list, const rational &timebase)
{
// If timebase is null, this will be an infinite loop
Q_ASSERT(!timebase.isNull());
QVector<rational> times;
foreach (const TimeRange &range, range_list) {
rational frame = Timecode::snap_time_to_timebase(range.in(), timebase, Timecode::kCeil);
while (frame < range.out()) {
times.append(frame);
frame += timebase;
}
}
return times;
}
QVector<rational> FrameHashCache::GetFrameListFromTimeRange(const TimeRangeList &range)
{
return GetFrameListFromTimeRange(range, timebase_);
}
QVector<rational> FrameHashCache::GetInvalidatedFrames()
{
return GetFrameListFromTimeRange(GetInvalidatedRanges());
}
QVector<rational> FrameHashCache::GetInvalidatedFrames(const TimeRange &intersecting)
{
return GetFrameListFromTimeRange(GetInvalidatedRanges().Intersects(intersecting));
}
bool FrameHashCache::SaveCacheFrame(const QByteArray& hash,
char* data,
const VideoParams& vparam,