forked from mia/Aegisub
Make AssFixStylesFilter an order of magnitude faster
Originally committed to SVN as r4580.
This commit is contained in:
parent
d1f36bdc43
commit
c64e764648
1 changed files with 10 additions and 31 deletions
|
@ -34,28 +34,24 @@
|
||||||
/// @ingroup export
|
/// @ingroup export
|
||||||
///
|
///
|
||||||
|
|
||||||
|
|
||||||
///////////
|
|
||||||
// Headers
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#ifndef AGI_PRE
|
||||||
|
#include <algorithm>
|
||||||
|
#include <functional>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "export_fixstyle.h"
|
#include "export_fixstyle.h"
|
||||||
#include "ass_file.h"
|
#include "ass_file.h"
|
||||||
#include "ass_dialogue.h"
|
#include "ass_dialogue.h"
|
||||||
#include "ass_style.h"
|
#include "ass_style.h"
|
||||||
|
|
||||||
|
|
||||||
/// @brief Constructor
|
/// @brief Constructor
|
||||||
///
|
|
||||||
AssFixStylesFilter::AssFixStylesFilter() {
|
AssFixStylesFilter::AssFixStylesFilter() {
|
||||||
initialized = false;
|
initialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// @brief Init
|
/// @brief Init
|
||||||
/// @return
|
|
||||||
///
|
|
||||||
void AssFixStylesFilter::Init() {
|
void AssFixStylesFilter::Init() {
|
||||||
if (initialized) return;
|
if (initialized) return;
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
@ -64,41 +60,24 @@ void AssFixStylesFilter::Init() {
|
||||||
description = _("Fixes styles by replacing any style that isn't available on file with Default.");
|
description = _("Fixes styles by replacing any style that isn't available on file with Default.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// @brief Process
|
/// @brief Process
|
||||||
/// @param subs
|
/// @param subs
|
||||||
/// @param export_dialog
|
/// @param export_dialog
|
||||||
///
|
|
||||||
void AssFixStylesFilter::ProcessSubs(AssFile *subs, wxWindow *export_dialog) {
|
void AssFixStylesFilter::ProcessSubs(AssFile *subs, wxWindow *export_dialog) {
|
||||||
// Build styles list
|
|
||||||
wxArrayString styles = subs->GetStyles();
|
wxArrayString styles = subs->GetStyles();
|
||||||
|
styles.Sort();
|
||||||
|
std::for_each(styles.begin(), styles.end(), std::mem_fun_ref(&wxString::MakeLower));
|
||||||
size_t n = styles.Count();
|
size_t n = styles.Count();
|
||||||
|
|
||||||
// Process lines
|
for (entryIter cur=subs->Line.begin();cur!=subs->Line.end();cur++) {
|
||||||
entryIter cur;
|
|
||||||
for (cur=subs->Line.begin();cur!=subs->Line.end();cur++) {
|
|
||||||
AssDialogue *diag = dynamic_cast<AssDialogue*>(*cur);
|
AssDialogue *diag = dynamic_cast<AssDialogue*>(*cur);
|
||||||
if (diag) {
|
if (diag) {
|
||||||
// Try to find style and match case
|
if (!std::binary_search(styles.begin(), styles.end(), diag->Style.Lower())) {
|
||||||
bool found = false;
|
diag->Style = L"Default";
|
||||||
for (size_t i=0;i<n;i++) {
|
}
|
||||||
if (diag->Style.Lower() == styles[i].Lower()) {
|
|
||||||
diag->Style = styles[i];
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Not found, fallback to default
|
|
||||||
if (!found) diag->Style = _T("Default");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// DOCME
|
/// DOCME
|
||||||
AssFixStylesFilter AssFixStylesFilter::instance;
|
AssFixStylesFilter AssFixStylesFilter::instance;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue