From 4fb2f4dcfb2d4dfaa3d0028ea8cd08aec7225a1f Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 20 May 2022 11:03:11 +0200 Subject: options: cache the profile list --- options/globals.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/options/globals.cpp b/options/globals.cpp index 386ef56d..963cab90 100644 --- a/options/globals.cpp +++ b/options/globals.cpp @@ -3,8 +3,10 @@ #include "defs.hpp" #include +#include #include #include +#include #include namespace options::globals::detail { @@ -124,9 +126,24 @@ QString ini_combine(const QString& filename) QStringList ini_list() { - QDir settings_dir(ini_directory()); + static QMutex mtx; + static QStringList list; + QMutexLocker l{&mtx}; + + const QString dirname = ini_directory(); + + { + static QDateTime last_time = {}; + auto time = QFileInfo{dirname}.lastModified(); + if (time == last_time) + return list; + last_time = time; + } + + QDir settings_dir(dirname); + using f = QDir::Filter; - auto list = settings_dir.entryList({ QStringLiteral("*.ini") }, f::Files | f::Readable, QDir::Name); + list = settings_dir.entryList({ QStringLiteral("*.ini") }, f::Files | f::Readable, QDir::Name); std::sort(list.begin(), list.end()); return list; } -- cgit v1.2.3