[vlmc-devel] [PATCH] RecentProjects: Use const QVariant& for toVariant()

Yikai Lu luyikei.qmltu at gmail.com
Tue Apr 12 08:37:26 CEST 2016


I totally forgot that SettingValue::get() is already QVariant, which should be used directly to save some memory.
---
 src/Project/RecentProjects.cpp | 8 ++++----
 src/Project/RecentProjects.h   | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/Project/RecentProjects.cpp b/src/Project/RecentProjects.cpp
index 4985d5b..25f43b5 100644
--- a/src/Project/RecentProjects.cpp
+++ b/src/Project/RecentProjects.cpp
@@ -30,16 +30,16 @@ RecentProjects::RecentProjects( Settings* vlmcSettings, QObject *parent )
                                                 "", "", SettingValue::Private );
 }
 
-QVariant
+const QVariant&
 RecentProjects::toVariant() const
 {
-    return QVariant( m_recentsProjects->get().toList() );
+    return m_recentsProjects->get();
 }
 
 void
 RecentProjects::remove( const QString &projectFile )
 {
-    QVariantList l = m_recentsProjects->get().toList();
+    QVariantList l = toVariant().toList();
     for ( int i = 0; i < l.count(); ++i )
     {
         if ( l[i].toMap()["file"].toString() == projectFile )
@@ -54,7 +54,7 @@ RecentProjects::remove( const QString &projectFile )
 void
 RecentProjects::projectLoaded( const QString& projectName, const QString& projectFile )
 {
-    QVariantList l = m_recentsProjects->get().toList();
+    QVariantList l = toVariant().toList();
     QVariantMap var {
         { "name", projectName },
         { "file", projectFile }
diff --git a/src/Project/RecentProjects.h b/src/Project/RecentProjects.h
index 82f5c44..6c5d6b3 100644
--- a/src/Project/RecentProjects.h
+++ b/src/Project/RecentProjects.h
@@ -36,7 +36,7 @@ class RecentProjects : public QObject
     public:
         explicit RecentProjects(Settings* vlmcSettings, QObject *parent = 0 );
 
-        QVariant        toVariant() const;
+        const QVariant& toVariant() const;
         void            remove( const QString& projectFile );
 
     public slots:
-- 
1.9.1



More information about the Vlmc-devel mailing list