Remove use of map-wrapper in adaptor 75/141475/5
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Mon, 31 Jul 2017 18:27:29 +0000 (19:27 +0100)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Thu, 17 Aug 2017 11:20:24 +0000 (12:20 +0100)
Change-Id: I1dc717f7322fe367ed4c19fc68628949632d2ce4

adaptors/common/object-profiler.cpp
adaptors/common/object-profiler.h

index 7d86bf0..47c771c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -57,21 +57,18 @@ ObjectProfiler::~ObjectProfiler()
 
 void ObjectProfiler::DisplayInstanceCounts()
 {
-  InstanceCountMapIterator iter = mInstanceCountMap.begin();
-  InstanceCountMapIterator end = mInstanceCountMap.end();
-
-  for( ; iter != end; iter++ )
+  for( auto&& element : mInstanceCountContainer )
   {
-    int memorySize = GetMemorySize(iter->first, iter->second);
+    int memorySize = GetMemorySize( element.first, element.second );
     if( memorySize > 0 )
     {
       LogMessage( Debug::DebugInfo, "%-30s: % 4d  Memory MemorySize: ~% 6.1f kB\n",
-                  iter->first.c_str(), iter->second, memorySize / 1024.0f );
+                  element.first.c_str(), element.second, memorySize / 1024.0f );
     }
     else
     {
       LogMessage( Debug::DebugInfo, "%-30s: % 4d\n",
-                  iter->first.c_str(), iter->second );
+                  element.first.c_str(), element.second );
     }
   }
   LogMessage(Debug::DebugInfo, "\n");
@@ -94,15 +91,19 @@ void ObjectProfiler::OnObjectCreated(BaseHandle handle)
 
   mInstanceTypes.push_back(InstanceTypePair(&handle.GetBaseObject(), theType));
 
-  InstanceCountMapIterator iter = mInstanceCountMap.find(theType);
-  if( iter == mInstanceCountMap.end() )
+  bool found = false;
+  for( auto&& element : mInstanceCountContainer )
   {
-    InstanceCountPair instanceCount(theType, 1);
-    mInstanceCountMap.insert(instanceCount);
+    if( element.first == theType )
+    {
+      element.second++;
+      found = true;
+    }
   }
-  else
+  if( !found )
   {
-    iter->second++;
+    InstanceCountPair instanceCount( theType, 1 );
+    mInstanceCountContainer.emplace_back( instanceCount );
   }
 }
 
@@ -110,22 +111,25 @@ void ObjectProfiler::OnObjectDestroyed(const Dali::RefObject* object)
 {
   const BaseObject* baseObject = static_cast<const BaseObject*>(object);
 
-  InstanceTypes::iterator end = mInstanceTypes.end();
-  for( InstanceTypes::iterator iter = mInstanceTypes.begin(); iter != end; iter++)
+  const auto end = mInstanceTypes.end();
+  for( auto iter = mInstanceTypes.begin(); iter != end; ++iter )
   {
     if( iter->first == baseObject )
     {
-      const std::string& theType = iter->second;
+      const auto& theType = iter->second;
       if( !theType.empty() )
       {
-        InstanceCountMapIterator countIter = mInstanceCountMap.find(theType);
-        if( countIter != mInstanceCountMap.end() )
+        auto&& countIter = std::find_if( mInstanceCountContainer.begin(),
+                                         mInstanceCountContainer.end(),
+                                         [theType] ( const InstanceCountPair& instance )
+                                                   { return instance.first == theType; } );
+        if( countIter != mInstanceCountContainer.end() )
         {
-          countIter->second--;
+          (*countIter).second--;
         }
       }
       mInstanceTypes.erase( iter );
-      break;
+      return;
     }
   }
 }
index eca7972..13a78c0 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_ADAPTOR_OBJECT_PROFILER_H__
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -19,9 +19,9 @@
  */
 
 // EXTERNAL INCLUDES
+#include <dali/public-api/common/vector-wrapper.h>
 #include <dali/public-api/object/object-registry.h>
 #include <dali/public-api/object/type-registry.h>
-#include <dali/devel-api/common/map-wrapper.h>
 #include <dali/public-api/signals/connection-tracker.h>
 
 // INTERNAL INCLUDES
@@ -81,16 +81,14 @@ private:
   int GetMemorySize(const std::string& name, int count);
 
 private:
-  typedef std::map<std::string, int> InstanceCountMap;
-  typedef std::pair<const std::string, int> InstanceCountPair;
-  typedef InstanceCountMap::iterator InstanceCountMapIterator;
-  typedef std::pair<BaseObject*, std::string> InstanceTypePair;
-  typedef std::vector<InstanceTypePair> InstanceTypes;
+
+  using InstanceCountPair = std::pair< const std::string, int >;
+  using InstanceTypePair = std::pair< BaseObject*, std::string >;
 
   Dali::ObjectRegistry    mObjectRegistry;
   Dali::Timer             mTimer;
-  InstanceCountMap        mInstanceCountMap;
-  InstanceTypes           mInstanceTypes;
+  std::vector< InstanceCountPair > mInstanceCountContainer;
+  std::vector< InstanceTypePair >  mInstanceTypes;
 };
 
 } // Adaptor