From df73591a54d94abd6dd85a644af2b44c89c2da21 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 8 Jul 2013 15:47:55 -0700 Subject: [PATCH] Load autoloaded automation scripts in parallel --- aegisub/src/auto4_base.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) 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)); } }