From 3b755fcd9af17e2aaee7a027179d320e9798ab2f Mon Sep 17 00:00:00 2001 From: Kimmo Hoikka Date: Thu, 16 Oct 2014 10:33:33 +0100 Subject: [PATCH] Removal of unnecessary use of std::set, part I [Problem] binary size [Cause] use of too many container types [Solution] stop using set Change-Id: I26e70c77733eb84086ce04112e7d65501aae01bd --- .../event/animation/animation-playlist.cpp | 24 ++++++++++++++-------- dali/internal/event/animation/animation-playlist.h | 7 ++++--- .../internal/event/common/object-registry-impl.cpp | 13 ------------ dali/internal/event/common/object-registry-impl.h | 7 ------- .../event/common/property-notification-manager.cpp | 17 ++++++++------- .../event/common/property-notification-manager.h | 5 ++--- dali/internal/render/shaders/program.h | 1 - dali/public-api/dali-core.h | 2 -- 8 files changed, 32 insertions(+), 44 deletions(-) diff --git a/dali/internal/event/animation/animation-playlist.cpp b/dali/internal/event/animation/animation-playlist.cpp index 7e27e55..866a400 100644 --- a/dali/internal/event/animation/animation-playlist.cpp +++ b/dali/internal/event/animation/animation-playlist.cpp @@ -46,25 +46,32 @@ AnimationPlaylist::~AnimationPlaylist() void AnimationPlaylist::AnimationCreated( Animation& animation ) { - mAnimations.insert( &animation ); + mAnimations.PushBack( &animation ); } void AnimationPlaylist::AnimationDestroyed( Animation& animation ) { - std::set< Animation* >::iterator iter = find( mAnimations.begin(), mAnimations.end(), &animation ); - DALI_ASSERT_ALWAYS( iter != mAnimations.end() && "Animation not found" ); + Dali::Vector< Animation* >::Iterator iter = std::find( mAnimations.Begin(), mAnimations.End(), &animation ); + DALI_ASSERT_ALWAYS( iter != mAnimations.End() && "Animation not found" ); - mAnimations.erase( iter ); + mAnimations.Remove( iter ); } void AnimationPlaylist::OnPlay( Animation& animation ) { - mPlaylist.insert( Dali::Animation(&animation) ); + mPlaylist.push_back( Dali::Animation(&animation) ); } void AnimationPlaylist::OnClear( Animation& animation ) { - mPlaylist.erase( Dali::Animation(&animation) ); + std::vector< Dali::Animation >::iterator iter = std::find( mPlaylist.begin(), mPlaylist.end(), Dali::Animation(&animation) ); + std::vector< Dali::Animation >::iterator last = mPlaylist.end(); + if( iter != last ) + { + --last; // move to real last + std::swap( *iter, *last ); // swap + mPlaylist.resize( mPlaylist.size() - 1u ); + } } void AnimationPlaylist::NotifyCompleted() @@ -73,7 +80,7 @@ void AnimationPlaylist::NotifyCompleted() // Since animations can be unreferenced during the signal emissions, iterators into animationPointers may be invalidated. // First copy and reference the finished animations, then emit signals - for ( std::set< Animation* >::iterator iter = mAnimations.begin(); iter != mAnimations.end(); ++iter ) + for ( Dali::Vector< Animation* >::Iterator iter = mAnimations.Begin(); iter != mAnimations.End(); ++iter ) { Animation* animation = *iter; @@ -83,7 +90,8 @@ void AnimationPlaylist::NotifyCompleted() // The animation may be present in mPlaylist - remove if necessary // Note that the animation "Finish" signal is emitted after Stop() has been called - mPlaylist.erase( Dali::Animation(animation) ); + std::vector< Dali::Animation >::iterator iter = std::find( mPlaylist.begin(), mPlaylist.end(), Dali::Animation(animation) ); + mPlaylist.erase( iter ); } } diff --git a/dali/internal/event/animation/animation-playlist.h b/dali/internal/event/animation/animation-playlist.h index ced67a7..504bc5f 100644 --- a/dali/internal/event/animation/animation-playlist.h +++ b/dali/internal/event/animation/animation-playlist.h @@ -20,7 +20,8 @@ // INTERNAL INCLUDES #include -#include +#include +#include #include namespace Dali @@ -94,8 +95,8 @@ private: // from CompleteNotificationInterface private: - std::set< Animation* > mAnimations; ///< All existing animations (not referenced) - std::set< Dali::Animation > mPlaylist; ///< The currently playing animations (reference counted) + Dali::Vector< Animation* > mAnimations; ///< All existing animations (not owned) + std::vector< Dali::Animation > mPlaylist; ///< The currently playing animations (owned through handle) }; diff --git a/dali/internal/event/common/object-registry-impl.cpp b/dali/internal/event/common/object-registry-impl.cpp index 906a200..65f605f 100644 --- a/dali/internal/event/common/object-registry-impl.cpp +++ b/dali/internal/event/common/object-registry-impl.cpp @@ -46,14 +46,6 @@ ObjectRegistry::~ObjectRegistry() void ObjectRegistry::RegisterObject( Dali::BaseObject* object ) { - // Assert than an object is only registered once - DALI_ASSERT_DEBUG( mDebugRegistry.end() == mDebugRegistry.find( object ) ); - -#ifdef DEBUG_ENABLED - // This allows us to assert that an object is only registered once (debug builds only) - mDebugRegistry.insert( object ); -#endif // DEBUG_ENABLED - if ( !mObjectCreatedSignalV2.Empty() ) { Dali::BaseHandle handle( object ); @@ -63,11 +55,6 @@ void ObjectRegistry::RegisterObject( Dali::BaseObject* object ) void ObjectRegistry::UnregisterObject( Dali::BaseObject* object ) { -#ifdef DEBUG_ENABLED - // This allows us to assert that an object is only registered once (debug builds only) - mDebugRegistry.erase( object ); -#endif // DEBUG_ENABLED - mObjectDestroyedSignalV2.Emit( object ); } diff --git a/dali/internal/event/common/object-registry-impl.h b/dali/internal/event/common/object-registry-impl.h index c85144c..3133b83 100644 --- a/dali/internal/event/common/object-registry-impl.h +++ b/dali/internal/event/common/object-registry-impl.h @@ -19,9 +19,6 @@ */ // INTERNAL INCLUDES -#ifdef DEBUG_ENABLED -#include -#endif #include #include #include @@ -121,10 +118,6 @@ private: Dali::ObjectRegistry::ObjectCreatedSignalV2 mObjectCreatedSignalV2; Dali::ObjectRegistry::ObjectDestroyedSignalV2 mObjectDestroyedSignalV2; -#ifdef DEBUG_ENABLED - std::set< Dali::BaseObject* > mDebugRegistry; ///< This allows us to assert that an object is only registered once (debug builds only) -#endif - }; } // namespace Internal diff --git a/dali/internal/event/common/property-notification-manager.cpp b/dali/internal/event/common/property-notification-manager.cpp index 235fbd4..54980c8 100644 --- a/dali/internal/event/common/property-notification-manager.cpp +++ b/dali/internal/event/common/property-notification-manager.cpp @@ -15,9 +15,12 @@ * */ -// INTERNAL INCLUDES +// CLASS HEADER #include + +// INTERNAL INCLUDES #include +#include namespace Dali { @@ -36,21 +39,21 @@ PropertyNotificationManager::~PropertyNotificationManager() void PropertyNotificationManager::PropertyNotificationCreated( PropertyNotification& propertyNotification ) { - mPropertyNotifications.insert( &propertyNotification ); + mPropertyNotifications.PushBack( &propertyNotification ); } void PropertyNotificationManager::PropertyNotificationDestroyed( PropertyNotification& propertyNotification ) { - std::set< PropertyNotification* >::iterator iter = std::find( mPropertyNotifications.begin(), mPropertyNotifications.end(), &propertyNotification ); - DALI_ASSERT_ALWAYS( iter != mPropertyNotifications.end() && "PropertyNotification not found" ); + Dali::Vector< PropertyNotification* >::Iterator iter = std::find( mPropertyNotifications.Begin(), mPropertyNotifications.End(), &propertyNotification ); + DALI_ASSERT_ALWAYS( iter != mPropertyNotifications.End() && "PropertyNotification not found" ); - mPropertyNotifications.erase( iter ); + mPropertyNotifications.Remove( iter ); } void PropertyNotificationManager::NotifyProperty( SceneGraph::PropertyNotification* propertyNotification, bool validity ) { - std::set< PropertyNotification* >::iterator iter = mPropertyNotifications.begin(); - std::set< PropertyNotification* >::iterator endIter = mPropertyNotifications.end(); + Dali::Vector< PropertyNotification* >::Iterator iter = mPropertyNotifications.Begin(); + const Dali::Vector< PropertyNotification* >::Iterator endIter = mPropertyNotifications.End(); // walk the collection of PropertyNotifications for( ; iter != endIter; ++iter ) diff --git a/dali/internal/event/common/property-notification-manager.h b/dali/internal/event/common/property-notification-manager.h index 97fc308..a5eef94 100644 --- a/dali/internal/event/common/property-notification-manager.h +++ b/dali/internal/event/common/property-notification-manager.h @@ -19,8 +19,7 @@ */ // INTERNAL INCLUDES -#include -#include +#include #include namespace Dali @@ -84,7 +83,7 @@ private: private: - std::set< PropertyNotification* > mPropertyNotifications; ///< All existing PropertyNotifications (not referenced) + Dali::Vector< PropertyNotification* > mPropertyNotifications; ///< All existing PropertyNotifications (not owned) }; diff --git a/dali/internal/render/shaders/program.h b/dali/internal/render/shaders/program.h index 341abb9..ab7cc6e 100644 --- a/dali/internal/render/shaders/program.h +++ b/dali/internal/render/shaders/program.h @@ -23,7 +23,6 @@ // INTERNAL INCLUDES #include -#include #include #include #include diff --git a/dali/public-api/dali-core.h b/dali/public-api/dali-core.h index d9ddbb7..3fdd352 100644 --- a/dali/public-api/dali-core.h +++ b/dali/public-api/dali-core.h @@ -53,8 +53,6 @@ #include #include #include -#include -#include #include #include #include -- 2.7.4