refactor ConnectionTracker class. 05/244205/5
authorSubhransu Mohanty <sub.mohanty@samsung.com>
Tue, 15 Sep 2020 09:32:14 +0000 (18:32 +0900)
committerSubhransu Mohanty <sub.mohanty@samsung.com>
Wed, 7 Oct 2020 00:37:53 +0000 (09:37 +0900)
- keep Dali::Vector<SlotConnection> instead of Dali::Vector<SlotConnection*>, this will
  reduce heap allocation as well as performance.

Change-Id: I1d0e89be58a41f89087708d8a59f2e0cbfa454df

dali/public-api/signals/connection-tracker.cpp
dali/public-api/signals/connection-tracker.h

index fbab2a4..ef7a4c5 100644 (file)
@@ -39,12 +39,11 @@ void ConnectionTracker::DisconnectAll()
 
   for(std::size_t i = 0; i < size; ++i)
   {
-    SlotConnection* connection = mConnections[i];
+    auto& connection = mConnections[i];
 
     // Tell the signal that the slot is disconnected
-    connection->GetSlotObserver()->SlotDisconnected(connection->GetCallback());
+    connection.GetSlotObserver()->SlotDisconnected(connection.GetCallback());
 
-    delete connection;
   }
 
   mConnections.Clear();
@@ -52,8 +51,7 @@ void ConnectionTracker::DisconnectAll()
 
 void ConnectionTracker::SignalConnected(SlotObserver* slotObserver, CallbackBase* callback)
 {
-  SlotConnection* connection = new SlotConnection(slotObserver, callback);
-  mConnections.PushBack(connection);
+  mConnections.PushBack(SlotConnection(slotObserver, callback));
 }
 
 void ConnectionTracker::SignalDisconnected(SlotObserver* signal, CallbackBase* callback)
@@ -62,17 +60,14 @@ void ConnectionTracker::SignalDisconnected(SlotObserver* signal, CallbackBase* c
 
   for(std::size_t i = 0; i < size; ++i)
   {
-    SlotConnection* connection = mConnections[i];
+    auto& connection = mConnections[i];
 
     // Pointer comparison i.e. SignalConnection contains pointer to same callback instance
-    if(connection->GetCallback() == callback)
+    if(connection.GetCallback() == callback)
     {
       // Remove from connection list
       mConnections.Erase(mConnections.Begin() + i);
 
-      // Delete connection
-      delete connection;
-
       // Disconnection complete
       return;
     }
index 2d1538a..d2f6262 100644 (file)
@@ -22,6 +22,7 @@
 #include <dali/public-api/common/dali-common.h>
 #include <dali/public-api/common/dali-vector.h>
 #include <dali/public-api/signals/connection-tracker-interface.h>
+#include <dali/public-api/signals/signal-slot-connections.h>
 
 namespace Dali
 {
@@ -83,7 +84,7 @@ private:
   ConnectionTracker& operator=(ConnectionTracker&&) = delete;      ///< Deleted move assignment operator. @SINCE_1_9.25
 
 private:
-  Dali::Vector<SlotConnection*> mConnections; ///< Vector of connection pointers
+  Dali::Vector<SlotConnection> mConnections; ///< Vector of connection
 };
 
 /**