Prevented parsed data from staying in memory, greatly reducing RAM usage

Originally committed to SVN as r91.
This commit is contained in:
Rodrigo Braz Monteiro 2006-02-21 03:13:35 +00:00
parent a82f60fe72
commit e41b6f9988
14 changed files with 53 additions and 24 deletions

View File

@ -96,12 +96,7 @@ AssDialogue::~AssDialogue () {
///////// /////////
// Clear // Clear
void AssDialogue::Clear () { void AssDialogue::Clear () {
using std::vector; ClearBlocks();
for (vector<AssDialogueBlock*>::iterator cur=Blocks.begin();cur!=Blocks.end();cur++) {
delete *cur;
}
Blocks.clear();
if( Tracker ) if( Tracker )
{ {
delete Tracker; delete Tracker;
@ -115,6 +110,17 @@ void AssDialogue::Clear () {
} }
////////////////
// Clear blocks
void AssDialogue::ClearBlocks() {
using std::vector;
for (vector<AssDialogueBlock*>::iterator cur=Blocks.begin();cur!=Blocks.end();cur++) {
delete *cur;
}
Blocks.clear();
}
////////////////// //////////////////
// Parse ASS Data // Parse ASS Data
bool AssDialogue::Parse(bool IsSSA) { bool AssDialogue::Parse(bool IsSSA) {
@ -392,8 +398,7 @@ void AssDialogue::ParseSRTTags () {
Text.Replace(_T("}{"),_T("")); Text.Replace(_T("}{"),_T(""));
// Update all stuff // Update all stuff
ParseASSTags(); //if (total > 0) UpdateText();
if (total > 0) UpdateText();
UpdateData(); UpdateData();
} }
@ -402,10 +407,7 @@ void AssDialogue::ParseSRTTags () {
// Parse ASS tags // Parse ASS tags
void AssDialogue::ParseASSTags () { void AssDialogue::ParseASSTags () {
// Clear blocks // Clear blocks
for (size_t i=0;i<Blocks.size();i++) { ClearBlocks();
delete Blocks.at(i);
}
Blocks.clear();
// Is drawing? // Is drawing?
int drawingLevel = 0; int drawingLevel = 0;
@ -490,6 +492,7 @@ void AssDialogue::ParseASSTags () {
void AssDialogue::StripTags () { void AssDialogue::StripTags () {
using std::list; using std::list;
using std::vector; using std::vector;
ParseASSTags();
vector<AssDialogueBlock*>::iterator next; vector<AssDialogueBlock*>::iterator next;
for (vector<AssDialogueBlock*>::iterator cur=Blocks.begin();cur!=Blocks.end();cur=next) { for (vector<AssDialogueBlock*>::iterator cur=Blocks.begin();cur!=Blocks.end();cur=next) {
next = cur; next = cur;
@ -501,6 +504,7 @@ void AssDialogue::StripTags () {
} }
UpdateText(); UpdateText();
UpdateData(); UpdateData();
ClearBlocks();
} }
@ -521,6 +525,7 @@ void AssDialogue::ConvertTagsToSRT () {
bool temp; bool temp;
// Iterate through blocks // Iterate through blocks
ParseASSTags();
for (size_t i=0;i<Blocks.size();i++) { for (size_t i=0;i<Blocks.size();i++) {
curBlock = AssDialogueBlock::GetAsOverride(Blocks.at(i)); curBlock = AssDialogueBlock::GetAsOverride(Blocks.at(i));
if (curBlock) { if (curBlock) {
@ -594,6 +599,7 @@ void AssDialogue::ConvertTagsToSRT () {
Text = final; Text = final;
UpdateData(); UpdateData();
ClearBlocks();
} }
@ -665,12 +671,14 @@ wxString AssDialogue::GetMarginString(int which) {
void AssDialogue::ProcessParameters(void (*callback)(wxString tagName,int par_n,AssOverrideParameter *param,void *userData),void *userData) { void AssDialogue::ProcessParameters(void (*callback)(wxString tagName,int par_n,AssOverrideParameter *param,void *userData),void *userData) {
// Apply for all override blocks // Apply for all override blocks
AssDialogueBlockOverride *curBlock; AssDialogueBlockOverride *curBlock;
//ParseASSTags();
for (std::vector<AssDialogueBlock*>::iterator cur=Blocks.begin();cur!=Blocks.end();cur++) { for (std::vector<AssDialogueBlock*>::iterator cur=Blocks.begin();cur!=Blocks.end();cur++) {
if ((*cur)->type == BLOCK_OVERRIDE) { if ((*cur)->type == BLOCK_OVERRIDE) {
curBlock = static_cast<AssDialogueBlockOverride*> (*cur); curBlock = static_cast<AssDialogueBlockOverride*> (*cur);
curBlock->ProcessParameters(callback,userData); curBlock->ProcessParameters(callback,userData);
} }
} }
//ClearBlocks();
} }

View File

@ -183,6 +183,7 @@ public:
void ProcessParameters(void (*callback)(wxString,int,AssOverrideParameter*,void *userData),void *userData=NULL); // Callback to process parameters void ProcessParameters(void (*callback)(wxString,int,AssOverrideParameter*,void *userData),void *userData=NULL); // Callback to process parameters
wxString GetSSAText(); wxString GetSSAText();
bool CollidesWith(AssDialogue *target); // Checks if two lines collide bool CollidesWith(AssDialogue *target); // Checks if two lines collide
void ClearBlocks();
AssDialogue(); AssDialogue();
AssDialogue(wxString data,bool IsSSA=false); AssDialogue(wxString data,bool IsSSA=false);

View File

@ -343,7 +343,7 @@ void AssFile::LoadTXT (wxString _filename,wxString encoding) {
line->Start.SetMS(0); line->Start.SetMS(0);
line->End.SetMS(0); line->End.SetMS(0);
line->UpdateData(); line->UpdateData();
line->ParseASSTags(); //line->ParseASSTags();
// Adds line // Adds line
Line.push_back(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:"))) { if ((data.Left(9) == _T("Dialogue:") || data.Left(8) == _T("Comment:"))) {
AssDialogue *diag = new AssDialogue(data,IsSSA); AssDialogue *diag = new AssDialogue(data,IsSSA);
lasttime = diag->Start.GetMS(); lasttime = diag->Start.GetMS();
diag->ParseASSTags(); //diag->ParseASSTags();
entry = diag; entry = diag;
entry->StartMS = lasttime; entry->StartMS = lasttime;
entry->group = group; entry->group = group;

View File

@ -142,7 +142,7 @@ void AudioKaraoke::Commit() {
finalText += wxString::Format(_T("{%s%i}"), syl->tag, syl->length) + syl->contents; finalText += wxString::Format(_T("{%s%i}"), syl->tag, syl->length) + syl->contents;
} }
diag->Text = finalText; diag->Text = finalText;
diag->ParseASSTags(); //diag->ParseASSTags();
} else { } else {
wxLogDebug(_T("Updating karaoke without rebuild")); wxLogDebug(_T("Updating karaoke without rebuild"));
for (size_t i = 0; i < n; i++) { for (size_t i = 0; i < n; i++) {
@ -185,7 +185,7 @@ void AudioKaraoke::AutoSplit() {
must_rebuild = true; must_rebuild = true;
AssDialogue newDiag(diag->data); AssDialogue newDiag(diag->data);
newDiag.Text = newText; newDiag.Text = newText;
newDiag.ParseASSTags(); //newDiag.ParseASSTags();
ParseDialogue(&newDiag); ParseDialogue(&newDiag);
} }
@ -205,6 +205,7 @@ bool AudioKaraoke::ParseDialogue(AssDialogue *curDiag) {
int pos = 0; int pos = 0;
temp.length = 0; temp.length = 0;
temp.position = 0; temp.position = 0;
curDiag->ParseASSTags();
size_t n = curDiag->Blocks.size(); size_t n = curDiag->Blocks.size();
bool foundOne = false; bool foundOne = false;
bool foundBlock = false; bool foundBlock = false;
@ -245,6 +246,7 @@ bool AudioKaraoke::ParseDialogue(AssDialogue *curDiag) {
// Last syllable // Last syllable
if (foundBlock) syllables.push_back(temp); if (foundBlock) syllables.push_back(temp);
return foundBlock; return foundBlock;
curDiag->ClearBlocks();
} }

View File

@ -1314,6 +1314,7 @@ void AutomationScript::process_lines(AssFile *input)
wxString ktext = _T(""); wxString ktext = _T("");
wxString ktext_stripped = _T(""); wxString ktext_stripped = _T("");
dia->ParseASSTags();
for (std::vector<AssDialogueBlock*>::iterator block = dia->Blocks.begin(); block != dia->Blocks.end(); block++) { for (std::vector<AssDialogueBlock*>::iterator block = dia->Blocks.begin(); block != dia->Blocks.end(); block++) {
switch ((*block)->type) { switch ((*block)->type) {
@ -1374,6 +1375,7 @@ void AutomationScript::process_lines(AssFile *input)
} }
} }
dia->ClearBlocks();
// add the final karaoke block to the table // 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) // (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"); e->Comment = kind == _T("comment");
lua_settop(L, -11); lua_settop(L, -11);
e->StartMS = e->Start.GetMS(); e->StartMS = e->Start.GetMS();
e->ParseASSTags(); //e->ParseASSTags();
e->UpdateData(); e->UpdateData();
input->Line.push_back(e); input->Line.push_back(e);
wxLogDebug(_T("Produced new dialogue event in output subs")); wxLogDebug(_T("Produced new dialogue event in output subs"));

View File

@ -384,6 +384,7 @@ void BaseGrid::DrawImage(wxDC &dc) {
} }
} }
} }
curDiag->ClearBlocks();
} }
// Show overrides // Show overrides

View File

@ -38,6 +38,7 @@ Please visit http://aegisub.net to download latest version
- Selected comments are now highlighted in a different color (AMZ) - Selected comments are now highlighted in a different color (AMZ)
- Added a volume slider bar to audio mode (AMZ) - Added a volume slider bar to audio mode (AMZ)
- Fixed behavior of deleting and joining lines on subtitles grid (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 =========================== = 1.09 beta - 2006.01.16 ===========================

View File

@ -194,6 +194,7 @@ void DialogResample::OnResample (wxCommandEvent &event) {
// Update // Update
curDiag->UpdateText(); curDiag->UpdateText();
curDiag->UpdateData(); curDiag->UpdateData();
curDiag->ClearBlocks();
continue; continue;
} }
catch (wchar_t *err) { catch (wchar_t *err) {

View File

@ -363,7 +363,7 @@ void SearchReplaceEngine::ReplaceNext(bool DoReplace) {
// Update // Update
AssDialogue *cur = grid->GetDialogue(curLine); AssDialogue *cur = grid->GetDialogue(curLine);
cur->ParseASSTags(); //cur->ParseASSTags();
cur->UpdateData(); cur->UpdateData();
// Commit // Commit
@ -454,7 +454,7 @@ void SearchReplaceEngine::ReplaceAll() {
if (replaced) { if (replaced) {
AssDialogue *cur = grid->GetDialogue(i); AssDialogue *cur = grid->GetDialogue(i);
cur->UpdateData(); cur->UpdateData();
cur->ParseASSTags(); //cur->ParseASSTags();
grid->SetRowToLine(i,cur); grid->SetRowToLine(i,cur);
} }
} }

View File

@ -548,6 +548,7 @@ void DialogSpellCheck::ComputeAction(int action) {
bool DialogSpellCheck::LineComputation() { bool DialogSpellCheck::LineComputation() {
AssDialogueBlockPlain *curPlain; AssDialogueBlockPlain *curPlain;
current_line->ParseASSTags();
size_t size_blocks = current_line->Blocks.size(); size_t size_blocks = current_line->Blocks.size();
for (size_t i=(curBlockNumber+1);i<size_blocks;i++) { for (size_t i=(curBlockNumber+1);i<size_blocks;i++) {
curPlain = AssDialogueBlock::GetAsPlain(current_line->Blocks.at(i)); curPlain = AssDialogueBlock::GetAsPlain(current_line->Blocks.at(i));
@ -559,10 +560,12 @@ bool DialogSpellCheck::LineComputation() {
} }
curPlain = 0; curPlain = 0;
curBlockNumber = -1; curBlockNumber = -1;
current_line->ClearBlocks();
return false; return false;
} }
void DialogSpellCheck::BlockStore() { void DialogSpellCheck::BlockStore() {
current_line->ParseASSTags();
AssDialogueBlockPlain *curPlain = AssDialogueBlock::GetAsPlain(current_line->Blocks.at(curBlockNumber)); AssDialogueBlockPlain *curPlain = AssDialogueBlock::GetAsPlain(current_line->Blocks.at(curBlockNumber));
if (curPlain) { if (curPlain) {
curPlain->text = current_block; curPlain->text = current_block;
@ -572,6 +575,7 @@ void DialogSpellCheck::BlockStore() {
subs->FlagAsModified(); subs->FlagAsModified();
} }
curPlain = 0; curPlain = 0;
current_line->ClearBlocks();
} }
#endif #endif

View File

@ -145,6 +145,7 @@ bool DialogTranslation::JumpToLine(int n,int block) {
// Count blocks // Count blocks
int nblocks = 0; int nblocks = 0;
current->ParseASSTags();
size_t size_blocks = current->Blocks.size(); size_t size_blocks = current->Blocks.size();
for (size_t i=0;i<size_blocks;i++) { for (size_t i=0;i<size_blocks;i++) {
if (current->Blocks.at(i)->type == BLOCK_PLAIN) nblocks++; if (current->Blocks.at(i)->type == BLOCK_PLAIN) nblocks++;
@ -207,6 +208,7 @@ bool DialogTranslation::JumpToLine(int n,int block) {
} }
OrigText->SetDefaultStyle(Normal); OrigText->SetDefaultStyle(Normal);
TransText->SetDefaultStyle(Normal); TransText->SetDefaultStyle(Normal);
current->ClearBlocks();
return true; return true;
} }
@ -298,6 +300,7 @@ void DialogTranslation::OnTransBoxKey(wxKeyEvent &event) {
if (Hotkeys.IsPressed(_T("Translation Assistant Accept")) || Hotkeys.IsPressed(_T("Translation Assistant Preview"))) { if (Hotkeys.IsPressed(_T("Translation Assistant Accept")) || Hotkeys.IsPressed(_T("Translation Assistant Preview"))) {
// Store // Store
AssDialogue *cur = grid->GetDialogue(curline); AssDialogue *cur = grid->GetDialogue(curline);
cur->ParseASSTags();
int nblock = -1; int nblock = -1;
for (unsigned int i=0;i<cur->Blocks.size();i++) { for (unsigned int i=0;i<cur->Blocks.size();i++) {
if (cur->Blocks.at(i)->type == BLOCK_PLAIN) nblock++; if (cur->Blocks.at(i)->type == BLOCK_PLAIN) nblock++;
@ -310,6 +313,7 @@ void DialogTranslation::OnTransBoxKey(wxKeyEvent &event) {
// Update line // Update line
cur->UpdateText(); cur->UpdateText();
cur->UpdateData(); cur->UpdateData();
cur->ClearBlocks();
grid->SetRowToLine(curline,cur); grid->SetRowToLine(curline,cur);
subs->FlagAsModified(); subs->FlagAsModified();
grid->CommitChanges(); grid->CommitChanges();
@ -331,6 +335,7 @@ void DialogTranslation::OnTransBoxKey(wxKeyEvent &event) {
using std::vector; using std::vector;
AssDialogueBlock *curBlock; AssDialogueBlock *curBlock;
int pos = -1; int pos = -1;
current->ParseASSTags();
for (vector<AssDialogueBlock*>::iterator cur=current->Blocks.begin();cur!=current->Blocks.end();cur++) { for (vector<AssDialogueBlock*>::iterator cur=current->Blocks.begin();cur!=current->Blocks.end();cur++) {
curBlock = *cur; curBlock = *cur;
if (curBlock->type == BLOCK_PLAIN) { if (curBlock->type == BLOCK_PLAIN) {
@ -340,6 +345,7 @@ void DialogTranslation::OnTransBoxKey(wxKeyEvent &event) {
} }
} }
} }
current->ClearBlocks();
return; return;
} }

View File

@ -256,11 +256,13 @@ void AssTransformFramerateFilter::TransformFrameRate(AssFile *subs) {
data.ko = 0; data.ko = 0;
// Process stuff // Process stuff
curDialogue->ParseASSTags();
curDialogue->ProcessParameters(TransformTimeTags,&data); curDialogue->ProcessParameters(TransformTimeTags,&data);
curDialogue->Start.SetMS(Input->CorrectTimeAtFrame(Output->CorrectFrameAtTime(curDialogue->Start.GetMS(),true),true)); 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->End.SetMS(Input->CorrectTimeAtFrame(Output->CorrectFrameAtTime(curDialogue->End.GetMS(),false),false));
curDialogue->UpdateText(); curDialogue->UpdateText();
curDialogue->UpdateData(); curDialogue->UpdateData();
curDialogue->ClearBlocks();
n++; n++;
} }
} }

View File

@ -874,7 +874,7 @@ void SubsEditBox::CommitText() {
// Update line // Update line
if (cur) { if (cur) {
cur->Text = TextEdit->GetValue(); cur->Text = TextEdit->GetValue();
cur->ParseASSTags(); //cur->ParseASSTags();
cur->UpdateData(); cur->UpdateData();
grid->SetRowToLine(linen,cur); grid->SetRowToLine(linen,cur);
audio->SetDialogue(grid,cur,linen); audio->SetDialogue(grid,cur,linen);
@ -1353,6 +1353,7 @@ void SubsEditBox::SetOverride (wxString tagname,wxString preValue,int forcePos)
// Commit changes and shift selection // Commit changes and shift selection
SetText(line->Text); SetText(line->Text);
line->ClearBlocks();
TextEdit->SetSelection(selstart+shift,selend+shift); TextEdit->SetSelection(selstart+shift,selend+shift);
TextEdit->SetFocus(); TextEdit->SetFocus();
} }

View File

@ -739,7 +739,7 @@ void SubtitlesGrid::On122Recombine(wxCommandEvent &event) {
while (n1->Text.Right(2) == _T("\\N") || n1->Text.Right(2) == _T("\\n")) while (n1->Text.Right(2) == _T("\\N") || n1->Text.Right(2) == _T("\\n"))
n1->Text = n1->Text.Mid(0,n1->Text.Length()-2); n1->Text = n1->Text.Mid(0,n1->Text.Length()-2);
n2->Start = n1->Start; n2->Start = n1->Start;
n1->ParseASSTags(); //n1->ParseASSTags();
n1->UpdateData(); n1->UpdateData();
n2->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")) while (n2->Text.Right(2) == _T("\\N") || n2->Text.Right(2) == _T("\\n"))
n2->Text = n2->Text.Mid(0,n2->Text.Length()-2); n2->Text = n2->Text.Mid(0,n2->Text.Length()-2);
n1->End = n2->End; n1->End = n2->End;
n2->ParseASSTags(); //n2->ParseASSTags();
n1->UpdateData(); n1->UpdateData();
n2->UpdateData(); n2->UpdateData();
@ -1307,8 +1307,8 @@ void SubtitlesGrid::SplitLine(int n,int pos,int mode) {
wxString orig = n1->Text; wxString orig = n1->Text;
n1->Text = orig.Left(pos); n1->Text = orig.Left(pos);
n2->Text = orig.Mid(pos); n2->Text = orig.Mid(pos);
n1->ParseASSTags(); //n1->ParseASSTags();
n2->ParseASSTags(); //n2->ParseASSTags();
// Modify time // Modify time
if (mode == 1) { if (mode == 1) {