Fix interface to avoid heap allocation. 63/244663/1
authorSubhransu Mohanty <sub.mohanty@samsung.com>
Wed, 23 Sep 2020 04:44:50 +0000 (13:44 +0900)
committerSubhransu Mohanty <sub.mohanty@samsung.com>
Wed, 23 Sep 2020 04:45:01 +0000 (13:45 +0900)
- take Property::Value and std::string by value.
- use vector::push_back(T&&) version to avoid copy.
- this patch reduces 300,000 memory allocation.

Change-Id: I2da12f4b18cef5967ada18d6c9c58d2bc406d8ea

dali/internal/event/animation/animation-impl.cpp
dali/internal/event/animation/animation-impl.h
dali/internal/event/common/object-impl.cpp
dali/internal/event/common/object-impl.h
dali/internal/event/common/property-metadata.h
dali/public-api/animation/animation.cpp

index dde0a5a..db41040 100644 (file)
@@ -422,22 +422,22 @@ void Animation::Clear()
   mPlaylist.OnClear( *this );
 }
 
-void Animation::AnimateBy( Property& target, Property::Value& relativeValue )
+void Animation::AnimateBy(Property& target, Property::Value relativeValue)
 {
-  AnimateBy( target, relativeValue, mDefaultAlpha, TimePeriod(mDurationSeconds) );
+  AnimateBy(target, std::move(relativeValue), mDefaultAlpha, TimePeriod(mDurationSeconds));
 }
 
-void Animation::AnimateBy( Property& target, Property::Value& relativeValue, AlphaFunction alpha )
+void Animation::AnimateBy(Property& target, Property::Value relativeValue, AlphaFunction alpha)
 {
-  AnimateBy( target, relativeValue, alpha, TimePeriod(mDurationSeconds) );
+  AnimateBy(target, std::move(relativeValue), alpha, TimePeriod(mDurationSeconds));
 }
 
-void Animation::AnimateBy( Property& target, Property::Value& relativeValue, TimePeriod period )
+void Animation::AnimateBy(Property& target, Property::Value relativeValue, TimePeriod period)
 {
-  AnimateBy( target, relativeValue, mDefaultAlpha, period );
+  AnimateBy(target, std::move(relativeValue), mDefaultAlpha, period);
 }
 
-void Animation::AnimateBy( Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period )
+void Animation::AnimateBy(Property& target, Property::Value relativeValue, AlphaFunction alpha, TimePeriod period)
 {
   Object& object = GetImplementation(target.object);
   const Property::Type propertyType = object.GetPropertyType( target.propertyIndex );
@@ -449,13 +449,8 @@ void Animation::AnimateBy( Property& target, Property::Value& relativeValue, Alp
 
   ExtendDuration(period);
 
-  // Store data to later notify the object that its property is being animated
-  ConnectorTargetValues connectorPair;
-  connectorPair.targetValue = relativeValue;
-  connectorPair.connectorIndex = mConnectors.Count();
-  connectorPair.timePeriod = period;
-  connectorPair.animatorType = Animation::BY;
-  mConnectorTargetValues.push_back( connectorPair );
+  // keep the current count.
+  auto connectorIndex = mConnectors.Count();
 
   // using destination type so component animation gets correct type
   switch ( destinationType )
@@ -541,27 +536,29 @@ void Animation::AnimateBy( Property& target, Property::Value& relativeValue, Alp
 
     default:
     {
-      // non animatable types handled already
+      DALI_ASSERT_DEBUG(false && "Property  not supported");
     }
   }
+  // Store data to later notify the object that its property is being animated
+  mConnectorTargetValues.push_back({std::move(relativeValue), period, connectorIndex, Animation::BY});
 }
 
-void Animation::AnimateTo( Property& target, Property::Value& destinationValue )
+void Animation::AnimateTo(Property& target, Property::Value destinationValue)
 {
-  AnimateTo( target, destinationValue, mDefaultAlpha, TimePeriod(mDurationSeconds) );
+  AnimateTo(target, std::move(destinationValue), mDefaultAlpha, TimePeriod(mDurationSeconds));
 }
 
-void Animation::AnimateTo( Property& target, Property::Value& destinationValue, AlphaFunction alpha )
+void Animation::AnimateTo(Property& target, Property::Value destinationValue, AlphaFunction alpha)
 {
-  AnimateTo( target, destinationValue, alpha, TimePeriod(mDurationSeconds));
+  AnimateTo(target, std::move(destinationValue), alpha, TimePeriod(mDurationSeconds));
 }
 
-void Animation::AnimateTo( Property& target, Property::Value& destinationValue, TimePeriod period )
+void Animation::AnimateTo(Property& target, Property::Value destinationValue, TimePeriod period)
 {
-  AnimateTo( target, destinationValue, mDefaultAlpha, period );
+  AnimateTo(target, std::move(destinationValue), mDefaultAlpha, period);
 }
 
-void Animation::AnimateTo( Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period )
+void Animation::AnimateTo(Property& target, Property::Value destinationValue, AlphaFunction alpha, TimePeriod period)
 {
   Object& object = GetImplementation( target.object );
   const Property::Type propertyType = object.GetPropertyType( target.propertyIndex );
@@ -573,13 +570,8 @@ void Animation::AnimateTo( Property& target, Property::Value& destinationValue,
 
   ExtendDuration( period );
 
-  // Store data to later notify the object that its property is being animated
-  ConnectorTargetValues connectorPair;
-  connectorPair.targetValue = destinationValue;
-  connectorPair.connectorIndex = mConnectors.Count();
-  connectorPair.timePeriod = period;
-  connectorPair.animatorType = Animation::TO;
-  mConnectorTargetValues.push_back( connectorPair );
+  // keep the current count.
+  auto connectorIndex = mConnectors.Count();
 
   // using destination type so component animation gets correct type
   switch ( destinationType )
@@ -663,9 +655,11 @@ void Animation::AnimateTo( Property& target, Property::Value& destinationValue,
 
     default:
     {
-      // non animatable types handled already
+      DALI_ASSERT_DEBUG(false && "Property  not supported");
     }
   }
+  // Store data to later notify the object that its property is being animated
+  mConnectorTargetValues.push_back({std::move(destinationValue), period, connectorIndex, Animation::TO});
 }
 
 void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames )
@@ -716,12 +710,7 @@ void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, Alp
   ExtendDuration( period );
 
   // Store data to later notify the object that its property is being animated
-  ConnectorTargetValues connectorPair;
-  connectorPair.targetValue = keyFrames.GetLastKeyFrameValue();
-  connectorPair.connectorIndex = mConnectors.Count();
-  connectorPair.timePeriod = period;
-  connectorPair.animatorType = BETWEEN;
-  mConnectorTargetValues.push_back( connectorPair );
+  mConnectorTargetValues.push_back({keyFrames.GetLastKeyFrameValue(), period, mConnectors.Count(), BETWEEN});
 
   // using destination type so component animation gets correct type
   switch( destinationType )
@@ -826,7 +815,7 @@ void Animation::AnimateBetween( Property target, const KeyFrames& keyFrames, Alp
 
     default:
     {
-      // non animatable types handled by keyframes
+      DALI_ASSERT_DEBUG(false && "Property  not supported");
     }
   }
 }
index a23223e..3820ade 100644 (file)
@@ -245,42 +245,42 @@ public:
   /**
    * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue)
    */
-  void AnimateBy(Property& target, Property::Value& relativeValue);
+  void AnimateBy(Property& target, Property::Value relativeValue);
 
   /**
    * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha)
    */
-  void AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha);
+  void AnimateBy(Property& target, Property::Value relativeValue, AlphaFunction alpha);
 
   /**
    * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, TimePeriod period)
    */
-  void AnimateBy(Property& target, Property::Value& relativeValue, TimePeriod period);
+  void AnimateBy(Property& target, Property::Value relativeValue, TimePeriod period);
 
   /**
    * @copydoc Dali::Animation::AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha, TimePeriod period)
    */
-  void AnimateBy(Property& target, Property::Value& relativeValue, AlphaFunction alpha, TimePeriod period);
+  void AnimateBy(Property& target, Property::Value relativeValue, AlphaFunction alpha, TimePeriod period);
 
   /**
    * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue)
    */
-  void AnimateTo(Property& target, Property::Value& destinationValue);
+  void AnimateTo(Property& target, Property::Value destinationValue);
 
   /**
    * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha)
    */
-  void AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha);
+  void AnimateTo(Property& target, Property::Value destinationValue, AlphaFunction alpha);
 
   /**
    * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, TimePeriod period)
    */
-  void AnimateTo(Property& target, Property::Value& destinationValue, TimePeriod period);
+  void AnimateTo(Property& target, Property::Value destinationValue, TimePeriod period);
 
   /**
    * @copydoc Dali::Animation::AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha, TimePeriod period)
    */
-  void AnimateTo(Property& target, Property::Value& destinationValue, AlphaFunction alpha, TimePeriod period);
+  void AnimateTo(Property& target, Property::Value destinationValue, AlphaFunction alpha, TimePeriod period);
 
   /**
    * @copydoc Dali::Animation::AnimateBetween(Property target, KeyFrames& keyFrames)
@@ -476,18 +476,20 @@ private:
 
   struct ConnectorTargetValues
   {
-    ConnectorTargetValues()
-    : targetValue(),
-      timePeriod( 0.0f ),
-      connectorIndex( 0 ),
-      animatorType( TO )
+    ConnectorTargetValues() = default;
+
+    ConnectorTargetValues(Property::Value value, TimePeriod time, std::size_t index, Animation::Type type)
+    : targetValue(std::move(value)),
+      timePeriod(time),
+      connectorIndex(index),
+      animatorType(type)
     {
     }
 
     Property::Value targetValue;
-    TimePeriod timePeriod;
-    std::size_t connectorIndex;
-    Animation::Type animatorType;
+    TimePeriod      timePeriod{0.f};
+    std::size_t     connectorIndex{0};
+    Animation::Type animatorType{TO};
   };
 
   enum class Notify
index bc6f9e9..811d3fa 100644 (file)
@@ -623,7 +623,7 @@ Property::Index Object::RegisterProperty(std::string          name,
       index = PROPERTY_CUSTOM_START_INDEX + static_cast<Property::Index>( mCustomProperties.Count() );
 
       CustomPropertyMetadata* customProperty =
-        new CustomPropertyMetadata(name, std::move(propertyValue), accessMode);
+        new CustomPropertyMetadata(std::move(name), std::move(propertyValue), accessMode);
 
       // Resolve index for the child property
       Object* parent = GetParentObject();
@@ -632,7 +632,7 @@ Property::Index Object::RegisterProperty(std::string          name,
         const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
         if( parentTypeInfo )
         {
-          Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex( name );
+          Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex( customProperty->name );
           if( childPropertyIndex != Property::INVALID_INDEX )
           {
             customProperty->childPropertyIndex = childPropertyIndex;
@@ -1066,7 +1066,7 @@ AnimatablePropertyMetadata* Object::FindAnimatableProperty( Property::Index inde
   return nullptr;
 }
 
-Property::Index Object::RegisterSceneGraphProperty( const std::string& name, Property::Index key, Property::Index index, const Property::Value& propertyValue ) const
+Property::Index Object::RegisterSceneGraphProperty( std::string name, Property::Index key, Property::Index index, Property::Value propertyValue ) const
 {
   // Create a new property
   Dali::Internal::OwnerPointer<PropertyBase> newProperty;
@@ -1147,11 +1147,11 @@ Property::Index Object::RegisterSceneGraphProperty( const std::string& name, Pro
   {
     DALI_ASSERT_ALWAYS( index <= PROPERTY_CUSTOM_MAX_INDEX && "Too many custom properties have been registered" );
 
-    mCustomProperties.PushBack( new CustomPropertyMetadata( name, key, propertyValue, property ) );
+    mCustomProperties.PushBack( new CustomPropertyMetadata( std::move(name), key, std::move(propertyValue), property ) );
   }
   else
   {
-    mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, propertyValue, property ) );
+    mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, std::move(propertyValue), property ) );
   }
 
   // queue a message to add the property
index a61fadd..64d9c8c 100644 (file)
@@ -435,7 +435,7 @@ protected:
    * @param [in] value The value of the property.
    * @return The index of the registered property or Property::INVALID_INDEX if registration failed.
    */
-  Property::Index RegisterSceneGraphProperty( const std::string& name, Property::Index key, Property::Index index, const Property::Value& propertyValue ) const;
+  Property::Index RegisterSceneGraphProperty( std::string name, Property::Index key, Property::Index index, Property::Value propertyValue ) const;
 
   /**
    * Registers animatable scene property
index f77e90f..a363ea1 100644 (file)
@@ -130,12 +130,12 @@ protected:
    * @param[in] sceneGraphProperty  A pointer to the scene-graph owned property
    * @param[in] writable            Whether the property is writable
    */
-  PropertyMetadata( const Property::Value& propertyValue,
+  PropertyMetadata( Property::Value propertyValue,
                     const SceneGraph::PropertyBase* sceneGraphProperty,
                     bool writable )
   : value( mStoredValue ),
     componentIndex( Property::INVALID_COMPONENT_INDEX ),
-    mStoredValue( propertyValue ),
+    mStoredValue( std::move(propertyValue) ),
     mSceneGraphProperty( sceneGraphProperty ),
     mWritable( writable )
   {
@@ -262,12 +262,12 @@ public:
    *
    * @note A valid sceneGraphProperty is mandatory otherwise this will debug assert.
    */
-  CustomPropertyMetadata( const std::string& propertyName,
+  CustomPropertyMetadata( std::string propertyName,
                           Property::Index propertyKey,
-                          const Property::Value& propertyValue,
+                          Property::Value propertyValue,
                           const SceneGraph::PropertyBase* sceneGraphProperty )
-  : PropertyMetadata( propertyValue, sceneGraphProperty, true ),
-    name( propertyName ),
+  : PropertyMetadata( std::move(propertyValue), sceneGraphProperty, true ),
+    name( std::move(propertyName) ),
     key( propertyKey ),
     childPropertyIndex( Property::INVALID_INDEX )
   {
@@ -282,11 +282,11 @@ public:
    *
    * @note The access mode MUST NOT be animatable otherwise this will debug assert.
    */
-  CustomPropertyMetadata( const std::string& propertyName,
-                          const Property::Value& propertyValue,
+  CustomPropertyMetadata( std::string propertyName,
+                          Property::Value propertyValue,
                           Property::AccessMode accessMode )
-  : PropertyMetadata( propertyValue, nullptr, ( accessMode != Property::READ_ONLY ) ),
-    name( propertyName ),
+  : PropertyMetadata( std::move(propertyValue), nullptr, ( accessMode != Property::READ_ONLY ) ),
+    name( std::move(propertyName) ),
     key( Property::INVALID_KEY ),
     childPropertyIndex( Property::INVALID_INDEX )
   {
index 1221a89..508280c 100644 (file)
@@ -177,42 +177,42 @@ Animation::AnimationSignalType& Animation::FinishedSignal()
 
 void Animation::AnimateBy(Property target, Property::Value relativeValue)
 {
-  GetImplementation(*this).AnimateBy(target, relativeValue);
+  GetImplementation(*this).AnimateBy(target, std::move(relativeValue));
 }
 
 void Animation::AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha)
 {
-  GetImplementation(*this).AnimateBy(target, relativeValue, alpha);
+  GetImplementation(*this).AnimateBy(target, std::move(relativeValue), alpha);
 }
 
 void Animation::AnimateBy(Property target, Property::Value relativeValue, TimePeriod period)
 {
-  GetImplementation(*this).AnimateBy(target, relativeValue, period);
+  GetImplementation(*this).AnimateBy(target, std::move(relativeValue), period);
 }
 
 void Animation::AnimateBy(Property target, Property::Value relativeValue, AlphaFunction alpha, TimePeriod period)
 {
-  GetImplementation(*this).AnimateBy(target, relativeValue, alpha, period);
+  GetImplementation(*this).AnimateBy(target, std::move(relativeValue), alpha, period);
 }
 
 void Animation::AnimateTo(Property target, Property::Value destinationValue)
 {
-  GetImplementation(*this).AnimateTo(target, destinationValue);
+  GetImplementation(*this).AnimateTo(target, std::move(destinationValue));
 }
 
 void Animation::AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha)
 {
-  GetImplementation(*this).AnimateTo(target, destinationValue, alpha);
+  GetImplementation(*this).AnimateTo(target, std::move(destinationValue), alpha);
 }
 
 void Animation::AnimateTo(Property target, Property::Value destinationValue, TimePeriod period)
 {
-  GetImplementation(*this).AnimateTo(target, destinationValue, period);
+  GetImplementation(*this).AnimateTo(target, std::move(destinationValue), period);
 }
 
 void Animation::AnimateTo(Property target, Property::Value destinationValue, AlphaFunction alpha, TimePeriod period)
 {
-  GetImplementation(*this).AnimateTo(target, destinationValue, alpha, period);
+  GetImplementation(*this).AnimateTo(target, std::move(destinationValue), alpha, period);
 }
 
 void Animation::AnimateBetween(Property target, KeyFrames& keyFrames)