From 330663c7b6d0faa7d10ec511d58b317a5ec37a19 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Fri, 14 Oct 2016 12:00:14 +0200 Subject: 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 --- src/qml/debugger/qqmlmemoryprofiler_p.h | 48 +++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 5 deletions(-) (limited to 'src/qml/debugger/qqmlmemoryprofiler_p.h') 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 +#include 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; }; -- cgit v1.2.3