[Konsole-devel] [PATCH] use a static _sessionRuntimeProfiles to store runtime profiles

Grissiom chaos.proton at gmail.com
Thu Sep 1 11:28:16 UTC 2011


Hi all,

I'm a KDE user from 4.0.1. But new to Konsole source code. When I went
through the source code last night I see a FIXME there. I think I
could fix it. So here is my patch:

============================
>From 5fb452e51ac1a9d18952fdd26f8bfa55438aedf3 Mon Sep 17 00:00:00 2001
From: Grissiom <chaos.proton at gmail.com>
Date: Thu, 1 Sep 2011 01:17:24 +0800
Subject: [PATCH 1/3] use a static _sessionRuntimeProfiles to store runtime
 profiles

---
 src/SessionManager.cpp |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/SessionManager.cpp b/src/SessionManager.cpp
index 028b76f..697589c 100644
--- a/src/SessionManager.cpp
+++ b/src/SessionManager.cpp
@@ -758,9 +758,7 @@ Profile::Ptr SessionManager::findByShortcut(const
QKeySequence& shortcut)

 void SessionManager::sessionProfileCommandReceived(const QString& text)
 {
-    // FIXME: This is inefficient, it creates a new profile instance for
-    // each set of changes applied.  Instead a new profile should be created
-    // only the first time changes are applied to a session
+    static QHash<Session*,Profile::Ptr> _sessionRuntimeProfiles;

     Session* session = qobject_cast<Session*>(sender());
     Q_ASSERT( session );
@@ -768,14 +766,23 @@ void
SessionManager::sessionProfileCommandReceived(const QString& text)
     ProfileCommandParser parser;
     QHash<Profile::Property,QVariant> changes = parser.parse(text);

-    Profile::Ptr newProfile = Profile::Ptr(new
Profile(_sessionProfiles[session]));
-
+    Profile::Ptr newProfile;
+    if (!_sessionRuntimeProfiles.contains(session))
+    {
+        newProfile = new Profile(_sessionProfiles[session]);
+        _sessionRuntimeProfiles.insert(session,newProfile);
+    }
+    else
+    {
+        newProfile = _sessionRuntimeProfiles[session];
+    }
+
     QHashIterator<Profile::Property,QVariant> iter(changes);
     while ( iter.hasNext() )
     {
         iter.next();
         newProfile->setProperty(iter.key(),iter.value());
-    }
+    }

     _sessionProfiles[session] = newProfile;
     applyProfile(newProfile,true);
-- 
1.7.5.1
============================

I'm not very familiar with the review board so far so I send the patch
to this dev mailing list.

Any comments are welcome ;)

P.S. I have other patches as well. If sending patches to this list is
acceptable, I will send them all soon.

-- 
Cheers,
Grissiom



More information about the konsole-devel mailing list