diff options
author | Erik Verbruggen <erik.verbruggen@qt.io> | 2016-10-14 12:00:14 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2016-10-14 11:55:25 +0000 |
commit | 330663c7b6d0faa7d10ec511d58b317a5ec37a19 (patch) | |
tree | 53bbaf3b70f5e8e7f602221858b7280294442e51 /src/qml/debugger/qqmlmemoryprofiler_p.h | |
parent | c204b176a5351d78e85bdc6ca78ee99429a81ff9 (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/qqmlmemoryprofiler_p.h')
-rw-r--r-- | src/qml/debugger/qqmlmemoryprofiler_p.h | 48 |
1 files changed, 43 insertions, 5 deletions
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; }; |