From 93d6e7a6b8d135365a0f073098ba97f905d2c550 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 17 Aug 2016 23:50:51 +0200 Subject: options: support deferred writes when saving bundles The mapping window has 13 bundles total in use. Setting them all can take up to a large fraction of a second on some windows filesystems. Do a single config write instead. --- options/bundle.cpp | 9 +++++++-- options/bundle.hpp | 1 + options/group.cpp | 12 ++++++++---- options/group.hpp | 2 ++ 4 files changed, 18 insertions(+), 6 deletions(-) (limited to 'options') diff --git a/options/bundle.cpp b/options/bundle.cpp index a60810c5..fa1a214c 100644 --- a/options/bundle.cpp +++ b/options/bundle.cpp @@ -37,7 +37,7 @@ bool bundle::contains(const QString &name) const return transient.contains(name); } -void bundle::save() +void bundle::save_deferred(QSettings& s) { if (group_name == "") return; @@ -51,7 +51,7 @@ void bundle::save() qDebug() << "bundle" << group_name << "changed, saving"; modified_ = true; saved = transient; - saved.save(); + saved.save_deferred(s); } } @@ -59,6 +59,11 @@ void bundle::save() emit saving(); } +void bundle::save() +{ + save_deferred(*group::ini_file()); +} + bool bundle::modifiedp() const // XXX unused { QMutexLocker l(const_cast(&mtx)); diff --git a/options/bundle.hpp b/options/bundle.hpp index 56d48f60..0283c911 100644 --- a/options/bundle.hpp +++ b/options/bundle.hpp @@ -41,6 +41,7 @@ public: void store_kv(const QString& name, const QVariant& datum); bool contains(const QString& name) const; void save(); + void save_deferred(QSettings& s); bool modifiedp() const; template diff --git a/options/group.cpp b/options/group.cpp index 8aa381fc..d710afad 100644 --- a/options/group.cpp +++ b/options/group.cpp @@ -23,15 +23,19 @@ group::group(const QString& name) : name(name) } void group::save() const +{ + save_deferred(*ini_file()); +} + +void group::save_deferred(QSettings& s) const { if (name == "") return; - auto s = ini_file(); - s->beginGroup(name); + s.beginGroup(name); for (auto& i : kvs) - s->setValue(i.first, i.second); - s->endGroup(); + s.setValue(i.first, i.second); + s.endGroup(); } void group::put(const QString &s, const QVariant &d) diff --git a/options/group.hpp b/options/group.hpp index 0deddfa8..05ef3b4b 100644 --- a/options/group.hpp +++ b/options/group.hpp @@ -1,6 +1,7 @@ #pragma once #include "export.hpp" +#include "compat/util.hpp" #include #include #include @@ -19,6 +20,7 @@ private: public: group(const QString& name); void save() const; + void save_deferred(QSettings& s) const; void put(const QString& s, const QVariant& d); bool contains(const QString& s) const; static QString ini_directory(); -- cgit v1.2.3