Speed up AsyncVideoProvider::UpdateSubtitles a bit

Adding Row to AssDialogue removes the need to loop over the file to find
out what rows changed.
This commit is contained in:
Thomas Goyne 2014-06-12 10:31:49 -07:00
parent 2508dd9c6e
commit a574d6ac67
1 changed files with 7 additions and 11 deletions

View File

@ -107,21 +107,17 @@ void AsyncVideoProvider::UpdateSubtitles(const AssFile *new_subs, std::set<const
// Copy just the lines which were changed, then replace the lines at the
// same indices in the worker's copy of the file with the new entries
std::vector<std::pair<size_t, AssDialogue*>> changed;
size_t i = 0;
for (auto const& e : new_subs->Events) {
if (changes.count(&e))
changed.emplace_back(i, new AssDialogue(e));
++i;
}
std::vector<AssDialogue *> changed;
for (auto d : changes)
changed.push_back(new AssDialogue(*d));
worker->Async([=]{
size_t i = 0;
int i = 0;
auto it = subs->Events.begin();
for (auto& update : changed) {
std::advance(it, update.first - i);
i = update.first;
subs->Events.insert(it, *update.second);
std::advance(it, update->Row - i);
i = update->Row;
subs->Events.insert(it, *update);
delete &*it--;
}