Significantly speed up duplicating multiple lines

SubtitlesGrid::DuplicateLines iterated over the entire file multiple
times for each line duplicated, making duplicating large numbers of
lines extremely slow.

Originally committed to SVN as r6366.
This commit is contained in:
Thomas Goyne 2012-01-26 20:08:54 +00:00
parent 15a4eca7ce
commit 99a7eece9c

View file

@ -371,34 +371,35 @@ void SubtitlesGrid::AdjoinLines(int n1,int n2,bool setStart) {
context->ass->Commit(_("adjoin"), AssFile::COMMIT_DIAG_TIME); context->ass->Commit(_("adjoin"), AssFile::COMMIT_DIAG_TIME);
} }
void SubtitlesGrid::DuplicateLines(int n1,int n2,bool nextFrame) { void SubtitlesGrid::DuplicateLines(int n1, int n2, bool nextFrame) {
AssDialogue *cur; std::list<AssEntry*>::iterator insert_pos = find(context->ass->Line.begin(), context->ass->Line.end(), GetDialogue(n2));
bool update = false; if (insert_pos != context->ass->Line.end())
int step=0; ++insert_pos;
for (int i=n1;i<=n2;i++) {
// Create Selection newsel;
if (i == n2) update = true;
cur = new AssDialogue(GetDialogue(i)->GetEntryData()); AssDialogue *first = 0;
for (int i = n1; i <= n2; ++i) {
AssDialogue *diag = new AssDialogue(*GetDialogue(i));
if (!first)
first = diag;
context->ass->Line.insert(insert_pos, diag);
newsel.insert(diag);
// Shift to next frame // Shift to next frame
if (nextFrame) { if (nextFrame) {
int posFrame = context->videoController->FrameAtTime(cur->End,agi::vfr::END) + 1; int posFrame = context->videoController->FrameAtTime(diag->End, agi::vfr::END) + 1;
cur->Start = context->videoController->TimeAtFrame(posFrame,agi::vfr::START); diag->Start = context->videoController->TimeAtFrame(posFrame, agi::vfr::START);
cur->End = context->videoController->TimeAtFrame(posFrame,agi::vfr::END); diag->End = context->videoController->TimeAtFrame(posFrame, agi::vfr::END);
} }
// Insert
InsertLine(cur,n2+step,true,update);
step++;
} }
// Select new lines context->ass->Commit(_("duplicate lines"), AssFile::COMMIT_DIAG_ADDREM);
Selection newsel;
for (int i=n1;i<=n2;i++) {
newsel.insert(GetDialogue(i+step));
}
SetSelectedSet(newsel); SetSelectedSet(newsel);
SetActiveLine(GetDialogue(n1+step)); SetActiveLine(first);
} }
/// @brief Retrieve a list of selected lines in the actual ASS file (ie. not as displayed in the grid but as represented in the file) /// @brief Retrieve a list of selected lines in the actual ASS file (ie. not as displayed in the grid but as represented in the file)