mirror of https://github.com/odrling/Aegisub
Significantly speed up AssDialogue::GetData
wxString::Format is astonishingly slow, and while this normally doesn't particularly matter, AssEntry::EntryData's speed can become relevant on large files. Switch to a slightly more manual approach that's about four times as fast.
This commit is contained in:
parent
a99428c49d
commit
7bc79b2d9f
|
@ -152,28 +152,49 @@ bool AssDialogue::Parse(wxString const& rawData) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString AssDialogue::GetData(bool ssa) const {
|
static void append_int(wxString &str, int v) {
|
||||||
wxString s = Style;
|
str += std::to_wstring(v);
|
||||||
wxString a = Actor;
|
str += ',';
|
||||||
wxString e = Effect;
|
}
|
||||||
s.Replace(",",";");
|
|
||||||
a.Replace(",",";");
|
|
||||||
e.Replace(",",";");
|
|
||||||
|
|
||||||
wxString str = wxString::Format(
|
static void append_str(wxString &out, wxString const& str) {
|
||||||
"%s: %s,%s,%s,%s,%s,%d,%d,%d,%s,%s",
|
out += str;
|
||||||
Comment ? "Comment" : "Dialogue",
|
out += ',';
|
||||||
ssa ? "Marked=0" : wxString::Format("%01d", Layer),
|
}
|
||||||
Start.GetAssFormated(),
|
|
||||||
End.GetAssFormated(),
|
static void append_unsafe_str(wxString &out, wxString const& str) {
|
||||||
s, a,
|
if (str.find(',') == str.npos)
|
||||||
Margin[0], Margin[1], Margin[2],
|
out += str;
|
||||||
e,
|
else {
|
||||||
Text.get());
|
wxString c = str;
|
||||||
|
c.Replace(wxS(","), wxS(";"));
|
||||||
|
out += c;
|
||||||
|
}
|
||||||
|
out += ',';
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString AssDialogue::GetData(bool ssa) const {
|
||||||
|
wxString str = Comment ? wxS("Comment: ") : wxS("Dialogue: ");
|
||||||
|
str.reserve(51 + Style.get().size() + Actor.get().size() + Effect.get().size() + Text.get().size());
|
||||||
|
|
||||||
|
if (ssa)
|
||||||
|
append_str(str, wxS("Marked=0"));
|
||||||
|
else
|
||||||
|
append_int(str, Layer);
|
||||||
|
append_str(str, Start.GetAssFormated());
|
||||||
|
append_str(str, End.GetAssFormated());
|
||||||
|
append_unsafe_str(str, Style);
|
||||||
|
append_unsafe_str(str, Actor);
|
||||||
|
for (int i = 0; i < 3; ++i)
|
||||||
|
append_int(str, Margin[i]);
|
||||||
|
append_unsafe_str(str, Effect);
|
||||||
|
str += Text.get();
|
||||||
|
|
||||||
// Make sure that final has no line breaks
|
// Make sure that final has no line breaks
|
||||||
str.Replace("\n", "");
|
if (str.find('\n') != str.npos || str.find('\r') != str.npos) {
|
||||||
str.Replace("\r", "");
|
str.Replace("\n", "");
|
||||||
|
str.Replace("\r", "");
|
||||||
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue