From e41b6f99885133ea0064136d68288f470e9f3b73 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Tue, 21 Feb 2006 03:13:35 +0000 Subject: [PATCH] Prevented parsed data from staying in memory, greatly reducing RAM usage Originally committed to SVN as r91. --- core/ass_dialogue.cpp | 32 ++++++++++++++++++++------------ core/ass_dialogue.h | 1 + core/ass_file.cpp | 4 ++-- core/audio_karaoke.cpp | 6 ++++-- core/automation.cpp | 4 +++- core/base_grid.cpp | 1 + core/changelog.txt | 1 + core/dialog_resample.cpp | 1 + core/dialog_search_replace.cpp | 4 ++-- core/dialog_spellcheck.cpp | 4 ++++ core/dialog_translation.cpp | 6 ++++++ core/export_framerate.cpp | 2 ++ core/subs_edit_box.cpp | 3 ++- core/subs_grid.cpp | 8 ++++---- 14 files changed, 53 insertions(+), 24 deletions(-) diff --git a/core/ass_dialogue.cpp b/core/ass_dialogue.cpp index 8fe96de5d..fdb973130 100644 --- a/core/ass_dialogue.cpp +++ b/core/ass_dialogue.cpp @@ -96,12 +96,7 @@ AssDialogue::~AssDialogue () { ///////// // Clear void AssDialogue::Clear () { - using std::vector; - for (vector::iterator cur=Blocks.begin();cur!=Blocks.end();cur++) { - delete *cur; - } - Blocks.clear(); - + ClearBlocks(); if( Tracker ) { delete Tracker; @@ -115,6 +110,17 @@ void AssDialogue::Clear () { } +//////////////// +// Clear blocks +void AssDialogue::ClearBlocks() { + using std::vector; + for (vector::iterator cur=Blocks.begin();cur!=Blocks.end();cur++) { + delete *cur; + } + Blocks.clear(); +} + + ////////////////// // Parse ASS Data bool AssDialogue::Parse(bool IsSSA) { @@ -392,8 +398,7 @@ void AssDialogue::ParseSRTTags () { Text.Replace(_T("}{"),_T("")); // Update all stuff - ParseASSTags(); - if (total > 0) UpdateText(); + //if (total > 0) UpdateText(); UpdateData(); } @@ -402,10 +407,7 @@ void AssDialogue::ParseSRTTags () { // Parse ASS tags void AssDialogue::ParseASSTags () { // Clear blocks - for (size_t i=0;i::iterator next; for (vector::iterator cur=Blocks.begin();cur!=Blocks.end();cur=next) { next = cur; @@ -501,6 +504,7 @@ void AssDialogue::StripTags () { } UpdateText(); UpdateData(); + ClearBlocks(); } @@ -521,6 +525,7 @@ void AssDialogue::ConvertTagsToSRT () { bool temp; // Iterate through blocks + ParseASSTags(); for (size_t i=0;i::iterator cur=Blocks.begin();cur!=Blocks.end();cur++) { if ((*cur)->type == BLOCK_OVERRIDE) { curBlock = static_cast (*cur); curBlock->ProcessParameters(callback,userData); } } + //ClearBlocks(); } diff --git a/core/ass_dialogue.h b/core/ass_dialogue.h index 2c1d5a00c..fc82bf29b 100644 --- a/core/ass_dialogue.h +++ b/core/ass_dialogue.h @@ -183,6 +183,7 @@ public: void ProcessParameters(void (*callback)(wxString,int,AssOverrideParameter*,void *userData),void *userData=NULL); // Callback to process parameters wxString GetSSAText(); bool CollidesWith(AssDialogue *target); // Checks if two lines collide + void ClearBlocks(); AssDialogue(); AssDialogue(wxString data,bool IsSSA=false); diff --git a/core/ass_file.cpp b/core/ass_file.cpp index 9778785e7..2f65167fb 100644 --- a/core/ass_file.cpp +++ b/core/ass_file.cpp @@ -343,7 +343,7 @@ void AssFile::LoadTXT (wxString _filename,wxString encoding) { line->Start.SetMS(0); line->End.SetMS(0); line->UpdateData(); - line->ParseASSTags(); + //line->ParseASSTags(); // Adds line Line.push_back(line); @@ -561,7 +561,7 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,bool &IsSSA) { if ((data.Left(9) == _T("Dialogue:") || data.Left(8) == _T("Comment:"))) { AssDialogue *diag = new AssDialogue(data,IsSSA); lasttime = diag->Start.GetMS(); - diag->ParseASSTags(); + //diag->ParseASSTags(); entry = diag; entry->StartMS = lasttime; entry->group = group; diff --git a/core/audio_karaoke.cpp b/core/audio_karaoke.cpp index 7140d92df..c8e1e46c6 100644 --- a/core/audio_karaoke.cpp +++ b/core/audio_karaoke.cpp @@ -142,7 +142,7 @@ void AudioKaraoke::Commit() { finalText += wxString::Format(_T("{%s%i}"), syl->tag, syl->length) + syl->contents; } diag->Text = finalText; - diag->ParseASSTags(); + //diag->ParseASSTags(); } else { wxLogDebug(_T("Updating karaoke without rebuild")); for (size_t i = 0; i < n; i++) { @@ -185,7 +185,7 @@ void AudioKaraoke::AutoSplit() { must_rebuild = true; AssDialogue newDiag(diag->data); newDiag.Text = newText; - newDiag.ParseASSTags(); + //newDiag.ParseASSTags(); ParseDialogue(&newDiag); } @@ -205,6 +205,7 @@ bool AudioKaraoke::ParseDialogue(AssDialogue *curDiag) { int pos = 0; temp.length = 0; temp.position = 0; + curDiag->ParseASSTags(); size_t n = curDiag->Blocks.size(); bool foundOne = false; bool foundBlock = false; @@ -245,6 +246,7 @@ bool AudioKaraoke::ParseDialogue(AssDialogue *curDiag) { // Last syllable if (foundBlock) syllables.push_back(temp); return foundBlock; + curDiag->ClearBlocks(); } diff --git a/core/automation.cpp b/core/automation.cpp index 1728190bd..f541cd449 100644 --- a/core/automation.cpp +++ b/core/automation.cpp @@ -1314,6 +1314,7 @@ void AutomationScript::process_lines(AssFile *input) wxString ktext = _T(""); wxString ktext_stripped = _T(""); + dia->ParseASSTags(); for (std::vector::iterator block = dia->Blocks.begin(); block != dia->Blocks.end(); block++) { switch ((*block)->type) { @@ -1374,6 +1375,7 @@ void AutomationScript::process_lines(AssFile *input) } } + dia->ClearBlocks(); // add the final karaoke block to the table // (even if there's no karaoke in the line, there's always at least one karaoke block) @@ -1552,7 +1554,7 @@ void AutomationScript::process_lines(AssFile *input) e->Comment = kind == _T("comment"); lua_settop(L, -11); e->StartMS = e->Start.GetMS(); - e->ParseASSTags(); + //e->ParseASSTags(); e->UpdateData(); input->Line.push_back(e); wxLogDebug(_T("Produced new dialogue event in output subs")); diff --git a/core/base_grid.cpp b/core/base_grid.cpp index 6ea45dddd..c0c8a6193 100644 --- a/core/base_grid.cpp +++ b/core/base_grid.cpp @@ -384,6 +384,7 @@ void BaseGrid::DrawImage(wxDC &dc) { } } } + curDiag->ClearBlocks(); } // Show overrides diff --git a/core/changelog.txt b/core/changelog.txt index f7d6514f0..89f7d4412 100644 --- a/core/changelog.txt +++ b/core/changelog.txt @@ -38,6 +38,7 @@ Please visit http://aegisub.net to download latest version - Selected comments are now highlighted in a different color (AMZ) - Added a volume slider bar to audio mode (AMZ) - Fixed behavior of deleting and joining lines on subtitles grid (AMZ) +- Fixed some internal workings, which should make Aegisub use considerably less RAM (especially for large Karaoke files, 3x less RAM usage measured) (AMZ) = 1.09 beta - 2006.01.16 =========================== diff --git a/core/dialog_resample.cpp b/core/dialog_resample.cpp index f3afea006..0b67ff988 100644 --- a/core/dialog_resample.cpp +++ b/core/dialog_resample.cpp @@ -194,6 +194,7 @@ void DialogResample::OnResample (wxCommandEvent &event) { // Update curDiag->UpdateText(); curDiag->UpdateData(); + curDiag->ClearBlocks(); continue; } catch (wchar_t *err) { diff --git a/core/dialog_search_replace.cpp b/core/dialog_search_replace.cpp index 2e4cc3461..18c8c12a0 100644 --- a/core/dialog_search_replace.cpp +++ b/core/dialog_search_replace.cpp @@ -363,7 +363,7 @@ void SearchReplaceEngine::ReplaceNext(bool DoReplace) { // Update AssDialogue *cur = grid->GetDialogue(curLine); - cur->ParseASSTags(); + //cur->ParseASSTags(); cur->UpdateData(); // Commit @@ -454,7 +454,7 @@ void SearchReplaceEngine::ReplaceAll() { if (replaced) { AssDialogue *cur = grid->GetDialogue(i); cur->UpdateData(); - cur->ParseASSTags(); + //cur->ParseASSTags(); grid->SetRowToLine(i,cur); } } diff --git a/core/dialog_spellcheck.cpp b/core/dialog_spellcheck.cpp index b8911094d..c17df6f6c 100644 --- a/core/dialog_spellcheck.cpp +++ b/core/dialog_spellcheck.cpp @@ -548,6 +548,7 @@ void DialogSpellCheck::ComputeAction(int action) { bool DialogSpellCheck::LineComputation() { AssDialogueBlockPlain *curPlain; + current_line->ParseASSTags(); size_t size_blocks = current_line->Blocks.size(); for (size_t i=(curBlockNumber+1);iBlocks.at(i)); @@ -559,10 +560,12 @@ bool DialogSpellCheck::LineComputation() { } curPlain = 0; curBlockNumber = -1; + current_line->ClearBlocks(); return false; } void DialogSpellCheck::BlockStore() { + current_line->ParseASSTags(); AssDialogueBlockPlain *curPlain = AssDialogueBlock::GetAsPlain(current_line->Blocks.at(curBlockNumber)); if (curPlain) { curPlain->text = current_block; @@ -572,6 +575,7 @@ void DialogSpellCheck::BlockStore() { subs->FlagAsModified(); } curPlain = 0; + current_line->ClearBlocks(); } #endif diff --git a/core/dialog_translation.cpp b/core/dialog_translation.cpp index df865bfc0..2bb1b6ff2 100644 --- a/core/dialog_translation.cpp +++ b/core/dialog_translation.cpp @@ -145,6 +145,7 @@ bool DialogTranslation::JumpToLine(int n,int block) { // Count blocks int nblocks = 0; + current->ParseASSTags(); size_t size_blocks = current->Blocks.size(); for (size_t i=0;iBlocks.at(i)->type == BLOCK_PLAIN) nblocks++; @@ -207,6 +208,7 @@ bool DialogTranslation::JumpToLine(int n,int block) { } OrigText->SetDefaultStyle(Normal); TransText->SetDefaultStyle(Normal); + current->ClearBlocks(); return true; } @@ -298,6 +300,7 @@ void DialogTranslation::OnTransBoxKey(wxKeyEvent &event) { if (Hotkeys.IsPressed(_T("Translation Assistant Accept")) || Hotkeys.IsPressed(_T("Translation Assistant Preview"))) { // Store AssDialogue *cur = grid->GetDialogue(curline); + cur->ParseASSTags(); int nblock = -1; for (unsigned int i=0;iBlocks.size();i++) { if (cur->Blocks.at(i)->type == BLOCK_PLAIN) nblock++; @@ -310,6 +313,7 @@ void DialogTranslation::OnTransBoxKey(wxKeyEvent &event) { // Update line cur->UpdateText(); cur->UpdateData(); + cur->ClearBlocks(); grid->SetRowToLine(curline,cur); subs->FlagAsModified(); grid->CommitChanges(); @@ -331,6 +335,7 @@ void DialogTranslation::OnTransBoxKey(wxKeyEvent &event) { using std::vector; AssDialogueBlock *curBlock; int pos = -1; + current->ParseASSTags(); for (vector::iterator cur=current->Blocks.begin();cur!=current->Blocks.end();cur++) { curBlock = *cur; if (curBlock->type == BLOCK_PLAIN) { @@ -340,6 +345,7 @@ void DialogTranslation::OnTransBoxKey(wxKeyEvent &event) { } } } + current->ClearBlocks(); return; } diff --git a/core/export_framerate.cpp b/core/export_framerate.cpp index fbbf6d81a..4087a0e3e 100644 --- a/core/export_framerate.cpp +++ b/core/export_framerate.cpp @@ -256,11 +256,13 @@ void AssTransformFramerateFilter::TransformFrameRate(AssFile *subs) { data.ko = 0; // Process stuff + curDialogue->ParseASSTags(); curDialogue->ProcessParameters(TransformTimeTags,&data); curDialogue->Start.SetMS(Input->CorrectTimeAtFrame(Output->CorrectFrameAtTime(curDialogue->Start.GetMS(),true),true)); curDialogue->End.SetMS(Input->CorrectTimeAtFrame(Output->CorrectFrameAtTime(curDialogue->End.GetMS(),false),false)); curDialogue->UpdateText(); curDialogue->UpdateData(); + curDialogue->ClearBlocks(); n++; } } diff --git a/core/subs_edit_box.cpp b/core/subs_edit_box.cpp index fc9506b96..5b88cc193 100644 --- a/core/subs_edit_box.cpp +++ b/core/subs_edit_box.cpp @@ -874,7 +874,7 @@ void SubsEditBox::CommitText() { // Update line if (cur) { cur->Text = TextEdit->GetValue(); - cur->ParseASSTags(); + //cur->ParseASSTags(); cur->UpdateData(); grid->SetRowToLine(linen,cur); audio->SetDialogue(grid,cur,linen); @@ -1353,6 +1353,7 @@ void SubsEditBox::SetOverride (wxString tagname,wxString preValue,int forcePos) // Commit changes and shift selection SetText(line->Text); + line->ClearBlocks(); TextEdit->SetSelection(selstart+shift,selend+shift); TextEdit->SetFocus(); } diff --git a/core/subs_grid.cpp b/core/subs_grid.cpp index dc42266c8..b06979b7e 100644 --- a/core/subs_grid.cpp +++ b/core/subs_grid.cpp @@ -739,7 +739,7 @@ void SubtitlesGrid::On122Recombine(wxCommandEvent &event) { while (n1->Text.Right(2) == _T("\\N") || n1->Text.Right(2) == _T("\\n")) n1->Text = n1->Text.Mid(0,n1->Text.Length()-2); n2->Start = n1->Start; - n1->ParseASSTags(); + //n1->ParseASSTags(); n1->UpdateData(); n2->UpdateData(); @@ -778,7 +778,7 @@ void SubtitlesGrid::On112Recombine(wxCommandEvent &event) { while (n2->Text.Right(2) == _T("\\N") || n2->Text.Right(2) == _T("\\n")) n2->Text = n2->Text.Mid(0,n2->Text.Length()-2); n1->End = n2->End; - n2->ParseASSTags(); + //n2->ParseASSTags(); n1->UpdateData(); n2->UpdateData(); @@ -1307,8 +1307,8 @@ void SubtitlesGrid::SplitLine(int n,int pos,int mode) { wxString orig = n1->Text; n1->Text = orig.Left(pos); n2->Text = orig.Mid(pos); - n1->ParseASSTags(); - n2->ParseASSTags(); + //n1->ParseASSTags(); + //n2->ParseASSTags(); // Modify time if (mode == 1) {