aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/debugger
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@qt.io>2016-10-14 12:00:14 +0200
committerErik Verbruggen <erik.verbruggen@qt.io>2016-10-14 11:55:25 +0000
commit330663c7b6d0faa7d10ec511d58b317a5ec37a19 (patch)
tree53bbaf3b70f5e8e7f602221858b7280294442e51 /src/qml/debugger
parentc204b176a5351d78e85bdc6ca78ee99429a81ff9 (diff)
QML: Prevent unnecessary QUrl->QString->QByteArray conversions
When QQmlMemoryProfiler is not used, do not convert the filename URL of a component to be converted from QUrl to a UTF8 char array. Change-Id: I741ec5b58678f3a25badac38f0198c9cff203eb1 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/debugger')
-rw-r--r--src/qml/debugger/qqmlmemoryprofiler.cpp37
-rw-r--r--src/qml/debugger/qqmlmemoryprofiler_p.h48
2 files changed, 55 insertions, 30 deletions
diff --git a/src/qml/debugger/qqmlmemoryprofiler.cpp b/src/qml/debugger/qqmlmemoryprofiler.cpp
index 60f6d96eaf..53d4e7ab21 100644
--- a/src/qml/debugger/qqmlmemoryprofiler.cpp
+++ b/src/qml/debugger/qqmlmemoryprofiler.cpp
@@ -38,18 +38,11 @@
****************************************************************************/
#include "qqmlmemoryprofiler_p.h"
-#include <QUrl>
QT_BEGIN_NAMESPACE
-enum LibraryState
-{
- Unloaded,
- Failed,
- Loaded
-};
-static LibraryState state = Unloaded;
+QQmlMemoryScope::LibraryState QQmlMemoryScope::state = QQmlMemoryScope::Unloaded;
typedef void (qmlmemprofile_stats)(int *allocCount, int *bytesAllocated);
typedef void (qmlmemprofile_clear)();
@@ -73,7 +66,7 @@ static qmlmemprofile_is_enabled *memprofile_is_enabled;
extern QFunctionPointer qt_linux_find_symbol_sys(const char *symbol);
#endif
-static bool openLibrary()
+bool QQmlMemoryScope::doOpenLibrary()
{
#if defined(Q_OS_LINUX) && !defined(QT_NO_LIBRARY)
if (state == Unloaded) {
@@ -97,28 +90,22 @@ static bool openLibrary()
return state == Loaded;
}
-QQmlMemoryScope::QQmlMemoryScope(const QUrl &url)
- : QQmlMemoryScope(url.path().toUtf8().constData())
-{
-}
-
-QQmlMemoryScope::QQmlMemoryScope(const char *string) : pushed(false)
+void QQmlMemoryScope::init(const char *string)
{
- if (openLibrary() && memprofile_is_enabled()) {
+ if (memprofile_is_enabled()) {
memprofile_push_location(string, 0);
pushed = true;
}
}
-QQmlMemoryScope::~QQmlMemoryScope()
+void QQmlMemoryScope::done()
{
- if (pushed)
- memprofile_pop_location();
+ memprofile_pop_location();
}
bool QQmlMemoryProfiler::isEnabled()
{
- if (openLibrary())
+ if (QQmlMemoryScope::openLibrary())
return memprofile_is_enabled();
return false;
@@ -126,31 +113,31 @@ bool QQmlMemoryProfiler::isEnabled()
void QQmlMemoryProfiler::enable()
{
- if (openLibrary())
+ if (QQmlMemoryScope::openLibrary())
memprofile_enable();
}
void QQmlMemoryProfiler::disable()
{
- if (openLibrary())
+ if (QQmlMemoryScope::openLibrary())
memprofile_disable();
}
void QQmlMemoryProfiler::clear()
{
- if (openLibrary())
+ if (QQmlMemoryScope::openLibrary())
memprofile_clear();
}
void QQmlMemoryProfiler::stats(int *allocCount, int *bytesAllocated)
{
- if (openLibrary())
+ if (QQmlMemoryScope::openLibrary())
memprofile_stats(allocCount, bytesAllocated);
}
void QQmlMemoryProfiler::save(const char *filename)
{
- if (openLibrary())
+ if (QQmlMemoryScope::openLibrary())
memprofile_save(filename);
}
diff --git a/src/qml/debugger/qqmlmemoryprofiler_p.h b/src/qml/debugger/qqmlmemoryprofiler_p.h
index 59f08704ca..fb71c999c3 100644
--- a/src/qml/debugger/qqmlmemoryprofiler_p.h
+++ b/src/qml/debugger/qqmlmemoryprofiler_p.h
@@ -52,6 +52,7 @@
//
#include <private/qtqmlglobal_p.h>
+#include <QUrl>
QT_BEGIN_NAMESPACE
@@ -62,16 +63,53 @@ QT_BEGIN_NAMESPACE
#else
-class QUrl;
-
class Q_QML_PRIVATE_EXPORT QQmlMemoryScope
{
public:
- explicit QQmlMemoryScope(const QUrl &url);
- explicit QQmlMemoryScope(const char *string);
- ~QQmlMemoryScope();
+ explicit QQmlMemoryScope(const QUrl &url)
+ : pushed(false)
+ {
+ if (Q_UNLIKELY(openLibrary()))
+ init(url.path().toUtf8().constData());
+ }
+
+ explicit QQmlMemoryScope(const char *string)
+ : pushed(false)
+ {
+ if (Q_UNLIKELY(openLibrary()))
+ init(string);
+ }
+
+ ~QQmlMemoryScope()
+ {
+ if (Q_UNLIKELY(pushed))
+ done();
+ }
+
+ enum LibraryState
+ {
+ Unloaded,
+ Failed,
+ Loaded
+ };
+
+ static bool openLibrary()
+ {
+ if (Q_LIKELY(state == Loaded))
+ return true;
+ if (state == Failed)
+ return false;
+
+ return doOpenLibrary();
+ }
private:
+ Q_NEVER_INLINE void init(const char *string);
+ Q_NEVER_INLINE void done();
+ Q_NEVER_INLINE static bool doOpenLibrary();
+
+ static LibraryState state;
+
bool pushed;
};