FileCatalog::getFileList(): speedup

This commit is contained in:
Ingo Weyrich
2019-07-14 15:23:28 +02:00
parent 72ae120bd1
commit 67e94e41c8

View File

@@ -566,44 +566,44 @@ void FileCatalog::closeDir ()
redrawAll (); redrawAll ();
} }
std::vector<Glib::ustring> FileCatalog::getFileList () std::vector<Glib::ustring> FileCatalog::getFileList()
{ {
BENCHFUN
std::vector<Glib::ustring> names; std::vector<Glib::ustring> names;
std::set<Glib::ustring> extensions; std::set<std::string> extensions;
for (const auto& parsedExt : options.parsedExtensions) { for (const auto& parsedExt : options.parsedExtensions) {
extensions.emplace (parsedExt.lowercase ()); extensions.emplace(parsedExt.lowercase());
} }
try { try {
auto dir = Gio::File::create_for_path (selectedDirectory); const auto dir = Gio::File::create_for_path(selectedDirectory);
auto enumerator = dir->enumerate_children ("standard::name"); auto enumerator = dir->enumerate_children("standard::name");
while (true) { while (true) {
try { try {
auto file = enumerator->next_file (); const auto file = enumerator->next_file();
if (!file) { if (!file) {
break; break;
} }
const Glib::ustring fname = file->get_name (); const Glib::ustring fname = file->get_name();
auto lastdot = fname.find_last_of ('.'); const auto lastdot = fname.find_last_of ('.');
if (lastdot >= fname.length () - 1) { if (lastdot >= fname.length () - 1) {
continue; continue;
} }
const auto fext = fname.substr (lastdot + 1).lowercase (); if (extensions.count(fname.substr(lastdot + 1).lowercase()) == 0) {
if (extensions.count (fext) == 0) {
continue; continue;
} }
names.emplace_back (Glib::build_filename (selectedDirectory, fname)); names.emplace_back(Glib::build_filename(selectedDirectory, fname));
} catch (Glib::Exception& exception) { } catch (Glib::Exception& exception) {
if (options.rtSettings.verbose) { if (options.rtSettings.verbose) {
std::cerr << exception.what () << std::endl; std::cerr << exception.what() << std::endl;
} }
} }
} }