From 877c4bf1b11917374b9f0ae96f8a0db6b243bca4 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Thu, 19 Apr 2007 15:22:47 +0000 Subject: [PATCH] Much faster subtitles loading (only really relevant for huge files, though) and undo stack operations. Originally committed to SVN as r1097. --- aegisub/ass_dialogue.cpp | 14 +++++++--- aegisub/ass_time.cpp | 13 +++++----- aegisub/subtitle_format_ass.cpp | 45 ++++++++++++++++++--------------- aegisub/text_file_reader.cpp | 40 ++++++++++++++++++----------- 4 files changed, 65 insertions(+), 47 deletions(-) diff --git a/aegisub/ass_dialogue.cpp b/aegisub/ass_dialogue.cpp index af883a7e1..1b77c7960 100644 --- a/aegisub/ass_dialogue.cpp +++ b/aegisub/ass_dialogue.cpp @@ -252,11 +252,11 @@ bool AssDialogue::Parse(wxString rawData, int version) { // Make data wxString AssDialogue::MakeData() { // Prepare - wxString final = _T(""); + static wxString final = _T(""); // Write all final - if (Comment) final += _T("Comment: "); - else final += _T("Dialogue: "); + if (Comment) final = _T("Comment: "); + else final = _T("Dialogue: "); final += wxString::Format(_T("%01i"),Layer); final += _T(","); @@ -279,6 +279,12 @@ wxString AssDialogue::MakeData() { Effect.Replace(_T(","),_T(";")); final += Effect + _T(","); final += Text; + + // Make sure that final has no line breaks + final.Replace(_T("\n"),_T("")); + final.Replace(_T("\r"),_T("")); + + // Return final return final; } @@ -824,7 +830,7 @@ AssEntry *AssDialogue::Clone() { final->StartMS = final->StartMS; final->Style = Style; final->Text = Text; - final->SetEntryData(GetEntryData()); + //final->SetEntryData(GetEntryData()); // Return return final; diff --git a/aegisub/ass_time.cpp b/aegisub/ass_time.cpp index 86e005b4f..ad4d955b6 100644 --- a/aegisub/ass_time.cpp +++ b/aegisub/ass_time.cpp @@ -67,20 +67,19 @@ void AssTime::ParseASS (const wxString _text) { try { // Hours - end = text.find(_T(":"),pos); - temp = text.SubString(pos,end-1); + end = text.Find(_T(':')); + temp = text.Left(end); if (!temp.ToLong(&th)) throw 0; pos = end+1; + text[end] = _T(' '); // Minutes - end = text.find(_T(":"),pos); - temp = text.SubString(pos,end-1); + end = text.Find(_T(':')); + temp = text.Mid(pos,end-pos); if (!temp.ToLong(&tm)) throw 0; - pos = end+1; // Seconds - end = text.length(); - temp = text.Mid(pos); + temp = text.Mid(end+1); if (!temp.ToDouble(&ts_raw)) throw 0; // Split into seconds and fraction diff --git a/aegisub/subtitle_format_ass.cpp b/aegisub/subtitle_format_ass.cpp index d6aaeeb9a..8b2c98092 100644 --- a/aegisub/subtitle_format_ass.cpp +++ b/aegisub/subtitle_format_ass.cpp @@ -95,27 +95,30 @@ void ASSSubtitleFormat::ReadFile(wxString filename,wxString encoding) { wxbuffer = file.ReadLineFromFile(); // Convert v4 styles to v4+ styles - // Ugly hacks to allow intermixed v4 and v4+ style sections - if (wxbuffer.Lower() == _T("[v4 styles]")) { - wxbuffer = _T("[V4+ Styles]"); - curgroup = wxbuffer; - version = 0; - } - else if (wxbuffer.Lower() == _T("[v4+ styles]")) { - curgroup = wxbuffer; - version = 1; - } - else if (wxbuffer.Lower() == _T("[v4++ styles]")) { - wxbuffer = _T("[V4+ Styles]"); - curgroup = wxbuffer; - version = 2; - } - // Not-so-special case for other groups, just set it - else if (!wxbuffer.IsEmpty() && wxbuffer[0] == _T('[')) { - curgroup = wxbuffer; - // default from extension in all other sections - //version = 1; - //if (filename.Right(4).Lower() == _T(".ssa")) version = 0; + if (!wxbuffer.IsEmpty() && wxbuffer[0] == _T('[')) { + // Ugly hacks to allow intermixed v4 and v4+ style sections + wxString low = wxbuffer.Lower(); + if (low == _T("[v4 styles]")) { + wxbuffer = _T("[V4+ Styles]"); + curgroup = wxbuffer; + version = 0; + } + else if (low == _T("[v4+ styles]")) { + curgroup = wxbuffer; + version = 1; + } + else if (low == _T("[v4++ styles]")) { + wxbuffer = _T("[V4+ Styles]"); + curgroup = wxbuffer; + version = 2; + } + // Not-so-special case for other groups, just set it + else { + curgroup = wxbuffer; + // default from extension in all other sections + //version = 1; + //if (filename.Right(4).Lower() == _T(".ssa")) version = 0; + } } // Add line diff --git a/aegisub/text_file_reader.cpp b/aegisub/text_file_reader.cpp index f1cd7e2aa..3bee3f7d7 100644 --- a/aegisub/text_file_reader.cpp +++ b/aegisub/text_file_reader.cpp @@ -184,7 +184,15 @@ void TextFileReader::SetEncodingConfiguration() { // Reads a line from file wxString TextFileReader::ReadLineFromFile() { Open(); - wxString wxbuffer = _T(""); + wxString wxbuffer; + int bufAlloc = 1024; + wxbuffer.Alloc(bufAlloc); +#ifdef TEXT_READER_USE_STDIO + char buffer[512]; + buffer[0] = 0; +#else + std::string buffer = ""; +#endif // Read UTF-16 line from file if (Is16) { @@ -212,6 +220,10 @@ wxString TextFileReader::ReadLineFromFile() { // Convert two chars into a widechar and append to string ch = *((wchar_t*)charbuffer); + if (wxbuffer.Length() == bufAlloc) { + bufAlloc *= 2; + wxbuffer.Alloc(bufAlloc); + } wxbuffer += ch; n++; } @@ -220,7 +232,6 @@ wxString TextFileReader::ReadLineFromFile() { // Read ASCII/UTF-8 line from file else { #ifdef TEXT_READER_USE_STDIO - char buffer[512]; while (1) { buffer[511] = '\1'; if (fgets(buffer, 512, file)) { @@ -240,31 +251,30 @@ wxString TextFileReader::ReadLineFromFile() { } } #else - std::string buffer; getline(file,buffer); - wxString lineresult(buffer.c_str(),*conv); - wxbuffer = lineresult; + wxbuffer = wxString(buffer.c_str(),*conv); #endif } // Remove line breaks - wxbuffer.Replace(_T("\r"),_T("")); - wxbuffer.Replace(_T("\n"),_T("")); - - // Final string - wxString final = wxString(wxbuffer); + //wxbuffer.Replace(_T("\r"),_T("\0")); + //wxbuffer.Replace(_T("\n"),_T("\0")); + size_t len=wxbuffer.Length(); + for (size_t i=0;i 0 && final[0] == 0xFEFF) { - final = final.Mid(1); + if (wxbuffer.Length() > 0 && wxbuffer[0] == 0xFEFF) { + wxbuffer = wxbuffer.Mid(1); } // Trim if (trim) { - final.Trim(true); - final.Trim(false); + wxbuffer.Trim(true); + wxbuffer.Trim(false); } - return final; + return wxbuffer; }