From 57d8fa7661c97fb9f02279060694a0073e7cc8b5 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 8 Dec 2016 05:34:07 +0100 Subject: options: get element with call operator thread_local is expensive. --- migration/20160917_00-accela.cpp | 2 +- options/bundle.cpp | 4 ++-- options/bundle.hpp | 6 +++--- options/tie.hpp | 12 ++++++------ options/value.hpp | 23 +++++++++++------------ 5 files changed, 23 insertions(+), 24 deletions(-) diff --git a/migration/20160917_00-accela.cpp b/migration/20160917_00-accela.cpp index 60104c24..aefe6dda 100644 --- a/migration/20160917_00-accela.cpp +++ b/migration/20160917_00-accela.cpp @@ -94,7 +94,7 @@ struct move_accela_to_sliders : migration tmp = val; } - value tmp(new_b, slider_name, slider_value(-1e6, s.rot_nonlinearity->min(), s.rot_nonlinearity->max())); + value tmp(new_b, slider_name, slider_value(-1e6, s.rot_nonlinearity().min(), s.rot_nonlinearity().max())); tmp = old_b->contains(slider_name) ? old_b->get(slider_name) : slider_value(1.1, 1, 1.75); diff --git a/options/bundle.cpp b/options/bundle.cpp index 96291476..74e08eb9 100644 --- a/options/bundle.cpp +++ b/options/bundle.cpp @@ -199,12 +199,12 @@ OPENTRACK_OPTIONS_EXPORT bundler& singleton() } // end options::detail -OPENTRACK_OPTIONS_EXPORT std::shared_ptr make_bundle(const QString& name) +OPENTRACK_OPTIONS_EXPORT std::shared_ptr make_bundle(const QString& name) { if (name.size()) return detail::singleton().make_bundle(name); else - return std::make_shared(QStringLiteral("")); + return std::make_shared(QStringLiteral("")); } QMutex* options::detail::bundle::get_mtx() const { return mtx; } diff --git a/options/bundle.hpp b/options/bundle.hpp index 2d7fa7f4..5bbe6f60 100644 --- a/options/bundle.hpp +++ b/options/bundle.hpp @@ -103,9 +103,9 @@ public: OPENTRACK_OPTIONS_EXPORT bundler& singleton(); } -using bundle_type = detail::bundle; -using bundle = std::shared_ptr; +using bundle_ = detail::bundle; +using bundle = std::shared_ptr; -OPENTRACK_OPTIONS_EXPORT std::shared_ptr make_bundle(const QString& name); +OPENTRACK_OPTIONS_EXPORT std::shared_ptr make_bundle(const QString& name); } diff --git a/options/tie.hpp b/options/tie.hpp index fcb4d60f..942c6098 100644 --- a/options/tie.hpp +++ b/options/tie.hpp @@ -131,8 +131,8 @@ inline void tie_setting(value& v, QSlider* w) const int q_min = w->minimum(); const int q_max = w->maximum(); - w->setValue(v->to_slider_pos(q_min, q_max)); - v = v->update_from_slider(w->value(), q_min, q_max); + w->setValue(v().to_slider_pos(q_min, q_max)); + v = v().update_from_slider(w->value(), q_min, q_max); } base_value::connect(w, @@ -144,8 +144,8 @@ inline void tie_setting(value& v, QSlider* w) { const int q_min = w->minimum(); const int q_max = w->maximum(); - v = v->update_from_slider(pos, q_min, q_max); - w->setValue(v->to_slider_pos(q_min, q_max)); + v = v().update_from_slider(pos, q_min, q_max); + w->setValue(v().to_slider_pos(q_min, q_max)); }); }, v.DIRECT_CONNTYPE); @@ -155,8 +155,8 @@ inline void tie_setting(value& v, QSlider* w) [=, &v](double) { const int q_min = w->minimum(); const int q_max = w->maximum(); - w->setValue(v->to_slider_pos(q_min, q_max)); - v = v->update_from_slider(w->value(), q_min, q_max); + w->setValue(v().to_slider_pos(q_min, q_max)); + v = v().update_from_slider(w->value(), q_min, q_max); }, v.SAFE_CONNTYPE); } diff --git a/options/value.hpp b/options/value.hpp index 3c45bf15..01746d67 100644 --- a/options/value.hpp +++ b/options/value.hpp @@ -166,14 +166,6 @@ public: { } - t get() const - { - t val = b->contains(self_name) - ? static_cast(b->get(self_name)) - : def; - return detail::value_get_traits::get(val, def); - } - t default_value() const { return def; @@ -191,13 +183,20 @@ public: emit valueChanged(static_cast>(get())); } - element_type const* operator->() const + element_type operator()() const { - static thread_local element_type last; - last = get(); - return &last; + return get(); } + private: + t get() const + { + t val = b->contains(self_name) + ? static_cast(b->get(self_name)) + : def; + return detail::value_get_traits::get(val, def); + } + const t def; }; -- cgit v1.2.3