diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-12-08 05:34:07 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-12-08 05:34:07 +0100 |
commit | 57d8fa7661c97fb9f02279060694a0073e7cc8b5 (patch) | |
tree | fef806825c73b9da2b0fad458a0c4488e756ff60 /options | |
parent | 4acd40cd2997b2702d9ab411a0c85d1a92a6189d (diff) |
options: get element with call operator
thread_local is expensive.
Diffstat (limited to 'options')
-rw-r--r-- | options/bundle.cpp | 4 | ||||
-rw-r--r-- | options/bundle.hpp | 6 | ||||
-rw-r--r-- | options/tie.hpp | 12 | ||||
-rw-r--r-- | options/value.hpp | 23 |
4 files changed, 22 insertions, 23 deletions
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<bundle_type> make_bundle(const QString& name) +OPENTRACK_OPTIONS_EXPORT std::shared_ptr<bundle_> make_bundle(const QString& name) { if (name.size()) return detail::singleton().make_bundle(name); else - return std::make_shared<bundle_type>(QStringLiteral("")); + return std::make_shared<bundle_>(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<bundle_type>; +using bundle_ = detail::bundle; +using bundle = std::shared_ptr<bundle_>; -OPENTRACK_OPTIONS_EXPORT std::shared_ptr<bundle_type> make_bundle(const QString& name); +OPENTRACK_OPTIONS_EXPORT std::shared_ptr<bundle_> 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<slider_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<slider_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<slider_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<t>(b->get<element_type>(self_name)) - : def; - return detail::value_get_traits<t>::get(val, def); - } - t default_value() const { return def; @@ -191,13 +183,20 @@ public: emit valueChanged(static_cast<detail::value_type_t<t>>(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<t>(b->get<element_type>(self_name)) + : def; + return detail::value_get_traits<t>::get(val, def); + } + const t def; }; |