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 // 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 // same indices in the worker's copy of the file with the new entries
std::vector<std::pair<size_t, AssDialogue*>> changed; std::vector<AssDialogue *> changed;
size_t i = 0; for (auto d : changes)
for (auto const& e : new_subs->Events) { changed.push_back(new AssDialogue(*d));
if (changes.count(&e))
changed.emplace_back(i, new AssDialogue(e));
++i;
}
worker->Async([=]{ worker->Async([=]{
size_t i = 0; int i = 0;
auto it = subs->Events.begin(); auto it = subs->Events.begin();
for (auto& update : changed) { for (auto& update : changed) {
std::advance(it, update.first - i); std::advance(it, update->Row - i);
i = update.first; i = update->Row;
subs->Events.insert(it, *update.second); subs->Events.insert(it, *update);
delete &*it--; delete &*it--;
} }