mirror of https://github.com/odrling/Aegisub
Destruct AssFiles on a background thread as it's rather slow with large files
Originally committed to SVN as r6407.
This commit is contained in:
parent
64553dd633
commit
8bef1eb874
|
@ -68,16 +68,14 @@ namespace std {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief AssFile constructor
|
|
||||||
AssFile::AssFile ()
|
AssFile::AssFile ()
|
||||||
: commitId(0)
|
: commitId(0)
|
||||||
, loaded(false)
|
, loaded(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief AssFile destructor
|
|
||||||
AssFile::~AssFile() {
|
AssFile::~AssFile() {
|
||||||
delete_clear(Line);
|
background_delete_clear(Line);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Load generic subs
|
/// @brief Load generic subs
|
||||||
|
@ -386,7 +384,7 @@ void AssFile::AddLine(wxString data, int *version, AssAttachment **attach) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssFile::Clear() {
|
void AssFile::Clear() {
|
||||||
delete_clear(Line);
|
background_delete_clear(Line);
|
||||||
|
|
||||||
loaded = false;
|
loaded = false;
|
||||||
filename.clear();
|
filename.clear();
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
|
|
||||||
#include <wx/icon.h>
|
#include <wx/icon.h>
|
||||||
#include <wx/menuitem.h>
|
#include <wx/menuitem.h>
|
||||||
|
#include <wx/thread.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class wxMouseEvent;
|
class wxMouseEvent;
|
||||||
|
@ -97,18 +98,53 @@ template<typename T> inline T mid(T a, T b, T c) { return std::max(a, std::min(b
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/// Polymorphic delete functor
|
||||||
struct delete_ptr {
|
struct delete_ptr {
|
||||||
template<class T>
|
template<class T>
|
||||||
void operator()(T* ptr) const {
|
void operator()(T* ptr) const {
|
||||||
delete ptr;
|
delete ptr;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Delete all of the items in a container of pointers and clear the container
|
||||||
template<class T>
|
template<class T>
|
||||||
void delete_clear(T& container) {
|
void delete_clear(T& container) {
|
||||||
|
if (!container.empty()) {
|
||||||
std::for_each(container.begin(), container.end(), delete_ptr());
|
std::for_each(container.begin(), container.end(), delete_ptr());
|
||||||
container.clear();
|
container.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Helper class for background_delete_clear
|
||||||
|
template<class Container>
|
||||||
|
class BackgroundDeleter : public wxThread {
|
||||||
|
Container cont;
|
||||||
|
wxThread::ExitCode Entry() {
|
||||||
|
delete_clear(cont);
|
||||||
|
return (wxThread::ExitCode)0;
|
||||||
|
}
|
||||||
|
public:
|
||||||
|
BackgroundDeleter(Container &source)
|
||||||
|
: wxThread(wxTHREAD_DETACHED)
|
||||||
|
{
|
||||||
|
using std::swap;
|
||||||
|
swap(cont, source);
|
||||||
|
|
||||||
|
SetPriority(WXTHREAD_MIN_PRIORITY);
|
||||||
|
Create();
|
||||||
|
Run();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Clear a container of pointers and delete the pointed to members on a
|
||||||
|
/// background thread
|
||||||
|
template<class T>
|
||||||
|
void background_delete_clear(T& container) {
|
||||||
|
if (!container.empty())
|
||||||
|
new BackgroundDeleter<T>(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Out>
|
template<class Out>
|
||||||
struct cast {
|
struct cast {
|
||||||
template<class In>
|
template<class In>
|
||||||
|
|
Loading…
Reference in New Issue