diff --git a/aegisub/src/auto4_base.cpp b/aegisub/src/auto4_base.cpp index 0ca69c5ea..d9a672ad2 100644 --- a/aegisub/src/auto4_base.cpp +++ b/aegisub/src/auto4_base.cpp @@ -56,6 +56,7 @@ #include #include #include +#include #include #include @@ -340,19 +341,25 @@ namespace Automation4 { { scripts.clear(); - int error_count = 0; + std::vector>> script_futures; boost::char_separator sep("|"); for (auto const& tok : boost::tokenizer>(path, sep)) { auto dirname = config::path->Decode(tok); if (!agi::fs::DirectoryExists(dirname)) continue; - for (auto filename : agi::fs::DirectoryIterator(dirname, "*.*")) { - auto s = ScriptFactory::CreateFromFile(dirname/filename, false, false); - if (s) { - if (!s->GetLoadedState()) ++error_count; - scripts.emplace_back(std::move(s)); - } + for (auto filename : agi::fs::DirectoryIterator(dirname, "*.*")) + script_futures.emplace_back(std::async(std::launch::async, [=] { + return ScriptFactory::CreateFromFile(dirname/filename, false, false); + })); + } + + int error_count = 0; + for (auto& future : script_futures) { + auto s = future.get(); + if (s) { + if (!s->GetLoadedState()) ++error_count; + scripts.emplace_back(std::move(s)); } }