diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2022-11-14 10:21:08 +0100 |
|---|---|---|
| committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2022-11-14 12:11:49 +0000 |
| commit | 560205ffa6338ebdeb3172e722158b9cfa54916c (patch) | |
| tree | 36108fe396c1de9bdf8f5a6402f4c877a0274074 /src | |
| parent | c016ab30c9c1932936424d22a0e62d3f1f2bfc48 (diff) | |
Profiler: Add move operations to FunctionCall
This requires us to check the pointer on destruction, but should make
list operations faster, due to the refcount becoming unnecessary.
It also fixes some compiler warnings.
Fixes: QTBUG-105226
Change-Id: I4b1fe65f08fa89b6b305c34e07e12ff5e165a9f7
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src')
| -rw-r--r-- | src/qml/jsruntime/qv4profiling.cpp | 1 | ||||
| -rw-r--r-- | src/qml/jsruntime/qv4profiling_p.h | 30 |
2 files changed, 25 insertions, 6 deletions
diff --git a/src/qml/jsruntime/qv4profiling.cpp b/src/qml/jsruntime/qv4profiling.cpp index db33cd27f9..ed0dba1809 100644 --- a/src/qml/jsruntime/qv4profiling.cpp +++ b/src/qml/jsruntime/qv4profiling.cpp @@ -63,6 +63,7 @@ void Profiler::reportData() for (const FunctionCall &call : std::as_const(m_data)) { properties.append(call.properties()); Function *function = call.function(); + Q_ASSERT(function); SentMarker &marker = m_sentLocations[reinterpret_cast<quintptr>(function)]; if (!marker.isValid()) { FunctionLocation &location = locations[properties.constLast().id]; diff --git a/src/qml/jsruntime/qv4profiling_p.h b/src/qml/jsruntime/qv4profiling_p.h index 61937e85ab..6fdd457f9d 100644 --- a/src/qml/jsruntime/qv4profiling_p.h +++ b/src/qml/jsruntime/qv4profiling_p.h @@ -102,9 +102,7 @@ struct MemoryAllocationProperties { class FunctionCall { public: - - FunctionCall() : m_function(nullptr), m_start(0), m_end(0) - { Q_ASSERT_X(false, Q_FUNC_INFO, "Cannot construct a function call without function"); } + FunctionCall() : m_function(nullptr), m_start(0), m_end(0) {} FunctionCall(Function *function, qint64 start, qint64 end) : m_function(function), m_start(start), m_end(end) @@ -114,13 +112,24 @@ public: m_function(other.m_function), m_start(other.m_start), m_end(other.m_end) { m_function->executableCompilationUnit()->addref(); } + FunctionCall(FunctionCall &&other) noexcept + : m_function(std::exchange(other.m_function, nullptr)) + , m_start(std::exchange(other.m_start, 0)) + , m_end(std::exchange(other.m_end, 0)) + {} + ~FunctionCall() - { m_function->executableCompilationUnit()->release(); } + { + if (m_function) + m_function->executableCompilationUnit()->release(); + } FunctionCall &operator=(const FunctionCall &other) { if (&other != this) { - other.m_function->executableCompilationUnit()->addref(); - m_function->executableCompilationUnit()->release(); + if (other.m_function) + other.m_function->executableCompilationUnit()->addref(); + if (m_function) + m_function->executableCompilationUnit()->release(); m_function = other.m_function; m_start = other.m_start; m_end = other.m_end; @@ -128,6 +137,15 @@ public: return *this; } + QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(FunctionCall) + + void swap(FunctionCall &other) noexcept + { + qt_ptr_swap(m_function, other.m_function); + std::swap(m_start, other.m_start); + std::swap(m_end, other.m_end); + } + Function *function() const { return m_function; |
