summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2019-05-21 12:46:54 +0200
committerMarc Mutz <marc.mutz@kdab.com>2019-05-21 12:48:11 +0200
commit2e835288562cf49d34037a3c4c1c326009688a44 (patch)
tree59b0cf292f157450520107a80492fe3bd20b5e78 /src
parent4b09d5a78d66f32e2bc51636ac4191aace279d8f (diff)
QScopeGuard: some cleanups
Use qExchange() in the move ctor and pass the function object by rvalue ref. This saves one move construction and doesn't produce unexpected results. The qScopeGuard free function should take the function object by value, because it decays and because we can't create an rvalure reference in a deduced context. But once we're inside qScopeGuard, the extra object isn't needed anymore, so optimize it away. Change-Id: I94cbc45f9bf6ca086e100efd922a0b4643a81671 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qscopeguard.h5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/corelib/tools/qscopeguard.h b/src/corelib/tools/qscopeguard.h
index 41d0a6af68..d20620e933 100644
--- a/src/corelib/tools/qscopeguard.h
+++ b/src/corelib/tools/qscopeguard.h
@@ -60,9 +60,8 @@ QScopeGuard
public:
QScopeGuard(QScopeGuard &&other) noexcept
: m_func(std::move(other.m_func))
- , m_invoke(other.m_invoke)
+ , m_invoke(qExchange(other.m_invoke, false))
{
- other.dismiss();
}
~QScopeGuard()
@@ -77,7 +76,7 @@ public:
}
private:
- explicit QScopeGuard(F f) noexcept
+ explicit QScopeGuard(F &&f) noexcept
: m_func(std::move(f))
{
}