From e3eaa6c6cf37a071ebbb472375137355d456c5ea Mon Sep 17 00:00:00 2001 From: Subhransu Mohanty Date: Wed, 7 Oct 2020 14:16:26 +0900 Subject: [PATCH] use string_view instead of const string literals. as constexpr stringview calculates the length of the string during compiletime. the == comparison is fast as it first checks whether the size of the both string are same before calling the expensive compare() function. Change-Id: I996faed4d82e5c478f5f55c31cfe25581aa4bbc9 --- automated-tests/src/dali/utc-Dali-Layer.cpp | 109 +++++++++++++++- automated-tests/src/dali/utc-Dali-Stage.cpp | 151 +++++++++++++++++++++++ dali/internal/event/actors/actor-impl.cpp | 75 +++++------ dali/internal/event/actors/layer-impl.cpp | 26 ++-- dali/internal/event/animation/animation-impl.cpp | 26 ++-- dali/internal/event/common/stage-impl.cpp | 49 ++++---- 6 files changed, 348 insertions(+), 88 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-Layer.cpp b/automated-tests/src/dali/utc-Dali-Layer.cpp index c3b5410..a74a42f 100644 --- a/automated-tests/src/dali/utc-Dali-Layer.cpp +++ b/automated-tests/src/dali/utc-Dali-Layer.cpp @@ -144,7 +144,7 @@ int UtcDaliLayerGetDepth(void) END_TEST; } -int UtcDaliLayerRaise(void) +int UtcDaliLayerRaise1(void) { tet_infoline("Testing Dali::Layer::Raise()"); TestApplication application; @@ -168,7 +168,34 @@ int UtcDaliLayerRaise(void) END_TEST; } -int UtcDaliLayerLower(void) +int UtcDaliLayerRaise2(void) +{ + tet_infoline("Testing Dali::Layer raise Action"); + TestApplication application; + Layer layer1 = Layer::New(); + Layer layer2 = Layer::New(); + + application.GetScene().Add(layer1); + application.GetScene().Add(layer2); + DALI_TEST_EQUALS(layer1.GetProperty(Layer::Property::DEPTH), 1u, TEST_LOCATION); + + layer1.Raise(); + DALI_TEST_EQUALS(layer1.GetProperty(Layer::Property::DEPTH), 2u, TEST_LOCATION); + + // get root + Layer root = application.GetScene().GetLayer(0); + DALI_TEST_EQUALS(root.GetProperty(Layer::Property::DEPTH), 0u, TEST_LOCATION); + + GetImplementation(root).DoAction("raise", Property::Map()); + + DALI_TEST_EQUALS(root.GetProperty(Layer::Property::DEPTH), 1u, TEST_LOCATION); + DALI_TEST_EQUALS(layer1.GetProperty(Layer::Property::DEPTH), 2u, TEST_LOCATION); + DALI_TEST_EQUALS(layer2.GetProperty(Layer::Property::DEPTH), 0u, TEST_LOCATION); + END_TEST; +} + + +int UtcDaliLayerLower1(void) { tet_infoline("Testing Dali::Layer::Lower()"); TestApplication application; @@ -192,7 +219,33 @@ int UtcDaliLayerLower(void) END_TEST; } -int UtcDaliLayerRaiseToTop(void) + +int UtcDaliLayerLower2(void) +{ + tet_infoline("Testing Dali::Layer lower Action"); + TestApplication application; + Layer layer1 = Layer::New(); + Layer layer2 = Layer::New(); + + application.GetScene().Add(layer1); + application.GetScene().Add(layer2); + DALI_TEST_EQUALS(layer2.GetProperty(Layer::Property::DEPTH), 2u, TEST_LOCATION); + + layer2.Lower(); + DALI_TEST_EQUALS(layer2.GetProperty(Layer::Property::DEPTH), 1u, TEST_LOCATION); + + // get root + Layer root = application.GetScene().GetLayer(0); + GetImplementation(root).DoAction("lower", Property::Map()); + DALI_TEST_EQUALS(root.GetProperty(Layer::Property::DEPTH), 0u, TEST_LOCATION); + + GetImplementation(layer2).DoAction("lower", Property::Map()); + DALI_TEST_EQUALS(root.GetProperty(Layer::Property::DEPTH), 1u, TEST_LOCATION); + DALI_TEST_EQUALS(layer2.GetProperty(Layer::Property::DEPTH), 0u, TEST_LOCATION); + END_TEST; +} + +int UtcDaliLayerRaiseToTop1(void) { tet_infoline("Testing Dali::Layer::RaiseToTop()"); TestApplication application; @@ -218,7 +271,33 @@ int UtcDaliLayerRaiseToTop(void) END_TEST; } -int UtcDaliLayerLowerToBottom(void) +int UtcDaliLayerRaiseToTop2(void) +{ + tet_infoline("Testing Dali::Layer raiseToTop Action"); + TestApplication application; + Layer layer1 = Layer::New(); + Layer layer2 = Layer::New(); + Layer layer3 = Layer::New(); + + application.GetScene().Add(layer1); + application.GetScene().Add(layer2); + application.GetScene().Add(layer3); + Layer root = application.GetScene().GetLayer(0); + + DALI_TEST_EQUALS(root.GetProperty(Layer::Property::DEPTH), 0u, TEST_LOCATION); + DALI_TEST_EQUALS(layer1.GetProperty(Layer::Property::DEPTH), 1u, TEST_LOCATION); + DALI_TEST_EQUALS(layer2.GetProperty(Layer::Property::DEPTH), 2u, TEST_LOCATION); + DALI_TEST_EQUALS(layer3.GetProperty(Layer::Property::DEPTH), 3u, TEST_LOCATION); + + GetImplementation(layer1).DoAction("raiseToTop", Property::Map()); + DALI_TEST_EQUALS(layer1.GetProperty(Layer::Property::DEPTH), 3u, TEST_LOCATION); + + GetImplementation(root).DoAction("raiseToTop", Property::Map()); + DALI_TEST_EQUALS(root.GetProperty(Layer::Property::DEPTH), 3u, TEST_LOCATION); + END_TEST; +} + +int UtcDaliLayerLowerToBottom1(void) { tet_infoline("Testing Dali::Layer::LowerToBottom()"); TestApplication application; @@ -239,6 +318,28 @@ int UtcDaliLayerLowerToBottom(void) END_TEST; } +int UtcDaliLayerLowerToBottom2(void) +{ + tet_infoline("Testing Dali::Layer lowerToBottom Action"); + TestApplication application; + Layer layer1 = Layer::New(); + Layer layer2 = Layer::New(); + Layer layer3 = Layer::New(); + + application.GetScene().Add(layer1); + application.GetScene().Add(layer2); + application.GetScene().Add(layer3); + + DALI_TEST_EQUALS(layer1.GetProperty(Layer::Property::DEPTH), 1u, TEST_LOCATION); + DALI_TEST_EQUALS(layer2.GetProperty(Layer::Property::DEPTH), 2u, TEST_LOCATION); + DALI_TEST_EQUALS(layer3.GetProperty(Layer::Property::DEPTH), 3u, TEST_LOCATION); + + GetImplementation(layer3).DoAction("lowerToBottom", Property::Map()); + DALI_TEST_EQUALS(layer3.GetProperty(Layer::Property::DEPTH), 0u, TEST_LOCATION); + END_TEST; +} + + int UtcDaliLayerSetClipping(void) { tet_infoline("Testing Dali::Layer::SetClipping()"); diff --git a/automated-tests/src/dali/utc-Dali-Stage.cpp b/automated-tests/src/dali/utc-Dali-Stage.cpp index 90fe393..303d672 100644 --- a/automated-tests/src/dali/utc-Dali-Stage.cpp +++ b/automated-tests/src/dali/utc-Dali-Stage.cpp @@ -178,6 +178,8 @@ struct TouchFunctor signalData.receivedTouchEvent = handle; } + // Allows functor to be used for signal connection by string. + // No data stored, though, so quite useless. void operator()() { signalData.functorCalled = true; @@ -222,6 +224,25 @@ struct WheelEventReceivedFunctor WheelEventSignalData& signalData; }; +// Functor that sets the data when wheel-event signal is received +struct WheelEventReceivedVoidFunctor +{ + WheelEventReceivedVoidFunctor(WheelEventSignalData& data) + : signalData(data) + { + } + + // Signals connected through BaseObject::DoConnectSignal can only take void() methods + bool operator()(void) + { + signalData.functorCalled = true; + return true; + } + + WheelEventSignalData& signalData; +}; + + bool DummyTouchCallback(Actor actor, const TouchEvent& touch) { return true; @@ -844,6 +865,27 @@ int UtcDaliStageEventProcessingFinishedP(void) END_TEST; } +int UtcDaliStageEventProcessingFinishedP2(void) +{ + TestApplication application; + Stage stage = Stage::GetCurrent(); + tet_printf("UtcDaliStageEventProcessingFinishedSignalP2 - check event processing finished signal connection by name\n"); + + bool eventProcessingFinished = false; + EventProcessingFinishedFunctor functor(eventProcessingFinished); + GetImplementation(stage).ConnectSignal(&application, "eventProcessingFinished", functor); + + Actor actor(Actor::New()); + stage.Add(actor); + + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(eventProcessingFinished); + + END_TEST; +} + int UtcDaliStageEventProcessingFinishedN(void) { TestApplication application; @@ -1103,6 +1145,35 @@ int UtcDaliStageTouchedSignalP(void) END_TEST; } + +int UtcDaliStageTouchedSignalP2(void) +{ + TestApplication application; + Stage stage = Stage::GetCurrent(); + tet_printf("UtcDaliStageTouchedSignalP2 - check touched signal connection by name\n"); + + TouchedSignalData data; + TouchFunctor functor(data); + GetImplementation(stage).ConnectSignal(&application, "touched", functor); + + // Render and notify. + application.SendNotification(); + application.Render(); + + // Basic test: No actors, single touch (down then up). + { + GenerateTouch(application, PointState::DOWN, Vector2(10.0f, 10.0f)); + + DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); + data.Reset(); + + GenerateTouch(application, PointState::UP, Vector2(10.0f, 10.0f)); + DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); + data.Reset(); + } + END_TEST; +} + int UtcDaliStageTouchedSignalN(void) { TestApplication application; @@ -1226,6 +1297,32 @@ int UtcDaliStageSignalWheelEventP(void) END_TEST; } + +int UtcDaliStageSignalWheelEventP2(void) +{ + TestApplication application; + Stage stage = Stage::GetCurrent(); + tet_printf("UtcDaliStageSignalWheelEventP2 - check wheel signal connection by name\n"); + + WheelEventSignalData data; + WheelEventReceivedVoidFunctor functor(data); + GetImplementation(stage).ConnectSignal(&application, "wheelEvent", functor); + + Integration::WheelEvent event(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), 1, 1000u); + application.ProcessEvent(event); + + DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); + // It's meaningless, since there's no data passed to the functor :/ + + data.Reset(); + + Integration::WheelEvent event2(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0u, Vector2(0.0f, 0.0f), -1, 1000u); + application.ProcessEvent(event2); + + DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); + END_TEST; +} + int UtcDaliStageContextLostSignalP(void) { TestApplication application; @@ -1242,6 +1339,23 @@ int UtcDaliStageContextLostSignalP(void) END_TEST; } +int UtcDaliStageContextLostSignalP2(void) +{ + TestApplication application; + Stage stage = Stage::GetCurrent(); + tet_printf("UtcDaliStageContextLostSignalP2 - check context loss signal connection by name\n"); + + bool contextLost = false; + ContextStatusFunctor contextLostFunctor(contextLost); + GetImplementation(stage).ConnectSignal(&application, "contextLost", contextLostFunctor); + + Integration::ContextNotifierInterface* notifier = application.GetCore().GetContextNotifier(); + notifier->NotifyContextLost(); + DALI_TEST_EQUALS(contextLost, true, TEST_LOCATION); + + END_TEST; +} + int UtcDaliStageContextLostSignalN(void) { TestApplication application; @@ -1283,6 +1397,27 @@ int UtcDaliStageContextRegainedSignalP(void) END_TEST; } +int UtcDaliStageContextRegainedSignalP2(void) +{ + TestApplication application; + Stage stage = Stage::GetCurrent(); + tet_printf("UtcDaliStageContextRegainedSignalP2 - check context regained signal connection by name\n"); + + bool contextRegained = false; + ContextStatusFunctor contextRegainedFunctor(contextRegained); + GetImplementation(stage).ConnectSignal(&application, "contextRegained", contextRegainedFunctor); + + Integration::ContextNotifierInterface* notifier = application.GetCore().GetContextNotifier(); + notifier->NotifyContextLost(); + notifier->NotifyContextRegained(); + DALI_TEST_EQUALS(contextRegained, true, TEST_LOCATION); + + END_TEST; +} + + + + int UtcDaliStageContextRegainedSignalN(void) { TestApplication application; @@ -1323,6 +1458,22 @@ int UtcDaliStageSceneCreatedSignalP(void) END_TEST; } +int UtcDaliStageSceneCreatedSignalP2(void) +{ + TestApplication application; + Stage stage = Stage::GetCurrent(); + + bool signalCalled = false; + SceneCreatedStatusFunctor sceneCreatedFunctor(signalCalled); + GetImplementation(stage).ConnectSignal(&application, "sceneCreated", sceneCreatedFunctor); + + Integration::Core& core = application.GetCore(); + core.SceneCreated(); + DALI_TEST_EQUALS(signalCalled, true, TEST_LOCATION); + + END_TEST; +} + int UtcDaliStageSceneCreatedSignalN(void) { TestApplication application; diff --git a/dali/internal/event/actors/actor-impl.cpp b/dali/internal/event/actors/actor-impl.cpp index f4a1067..bdd3d94 100755 --- a/dali/internal/event/actors/actor-impl.cpp +++ b/dali/internal/event/actors/actor-impl.cpp @@ -148,21 +148,21 @@ DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX, ActorDefaultPropert // Signals -const char* const SIGNAL_HOVERED = "hovered"; -const char* const SIGNAL_WHEEL_EVENT = "wheelEvent"; -const char* const SIGNAL_ON_SCENE = "onScene"; -const char* const SIGNAL_OFF_SCENE = "offScene"; -const char* const SIGNAL_ON_RELAYOUT = "onRelayout"; -const char* const SIGNAL_TOUCHED = "touched"; -const char* const SIGNAL_VISIBILITY_CHANGED = "visibilityChanged"; -const char* const SIGNAL_LAYOUT_DIRECTION_CHANGED = "layoutDirectionChanged"; -const char* const SIGNAL_CHILD_ADDED = "childAdded"; -const char* const SIGNAL_CHILD_REMOVED = "childRemoved"; +static constexpr std::string_view SIGNAL_HOVERED = "hovered"; +static constexpr std::string_view SIGNAL_WHEEL_EVENT = "wheelEvent"; +static constexpr std::string_view SIGNAL_ON_SCENE = "onScene"; +static constexpr std::string_view SIGNAL_OFF_SCENE = "offScene"; +static constexpr std::string_view SIGNAL_ON_RELAYOUT = "onRelayout"; +static constexpr std::string_view SIGNAL_TOUCHED = "touched"; +static constexpr std::string_view SIGNAL_VISIBILITY_CHANGED = "visibilityChanged"; +static constexpr std::string_view SIGNAL_LAYOUT_DIRECTION_CHANGED = "layoutDirectionChanged"; +static constexpr std::string_view SIGNAL_CHILD_ADDED = "childAdded"; +static constexpr std::string_view SIGNAL_CHILD_REMOVED = "childRemoved"; // Actions -const char* const ACTION_SHOW = "show"; -const char* const ACTION_HIDE = "hide"; +static constexpr std::string_view ACTION_SHOW = "show"; +static constexpr std::string_view ACTION_HIDE = "hide"; BaseHandle CreateActor() { @@ -171,19 +171,19 @@ BaseHandle CreateActor() TypeRegistration mType( typeid(Dali::Actor), typeid(Dali::Handle), CreateActor, ActorDefaultProperties ); -SignalConnectorType signalConnector2( mType, SIGNAL_HOVERED, &Actor::DoConnectSignal ); -SignalConnectorType signalConnector3( mType, SIGNAL_WHEEL_EVENT, &Actor::DoConnectSignal ); -SignalConnectorType signalConnector4( mType, SIGNAL_ON_SCENE, &Actor::DoConnectSignal ); -SignalConnectorType signalConnector5( mType, SIGNAL_OFF_SCENE, &Actor::DoConnectSignal ); -SignalConnectorType signalConnector6( mType, SIGNAL_ON_RELAYOUT, &Actor::DoConnectSignal ); -SignalConnectorType signalConnector7( mType, SIGNAL_TOUCHED, &Actor::DoConnectSignal ); -SignalConnectorType signalConnector8( mType, SIGNAL_VISIBILITY_CHANGED, &Actor::DoConnectSignal ); -SignalConnectorType signalConnector9( mType, SIGNAL_LAYOUT_DIRECTION_CHANGED, &Actor::DoConnectSignal ); -SignalConnectorType signalConnector10( mType, SIGNAL_CHILD_ADDED, &Actor::DoConnectSignal ); -SignalConnectorType signalConnector11( mType, SIGNAL_CHILD_REMOVED, &Actor::DoConnectSignal ); +SignalConnectorType signalConnector2(mType, std::string(SIGNAL_HOVERED), &Actor::DoConnectSignal); +SignalConnectorType signalConnector3(mType, std::string(SIGNAL_WHEEL_EVENT), &Actor::DoConnectSignal); +SignalConnectorType signalConnector4(mType, std::string(SIGNAL_ON_SCENE), &Actor::DoConnectSignal); +SignalConnectorType signalConnector5(mType, std::string(SIGNAL_OFF_SCENE), &Actor::DoConnectSignal); +SignalConnectorType signalConnector6(mType, std::string(SIGNAL_ON_RELAYOUT), &Actor::DoConnectSignal); +SignalConnectorType signalConnector7(mType, std::string(SIGNAL_TOUCHED), &Actor::DoConnectSignal); +SignalConnectorType signalConnector8(mType, std::string(SIGNAL_VISIBILITY_CHANGED), &Actor::DoConnectSignal); +SignalConnectorType signalConnector9(mType, std::string(SIGNAL_LAYOUT_DIRECTION_CHANGED), &Actor::DoConnectSignal); +SignalConnectorType signalConnector10(mType, std::string(SIGNAL_CHILD_ADDED), &Actor::DoConnectSignal); +SignalConnectorType signalConnector11(mType, std::string(SIGNAL_CHILD_REMOVED), &Actor::DoConnectSignal); -TypeAction a1( mType, ACTION_SHOW, &Actor::DoAction ); -TypeAction a2( mType, ACTION_HIDE, &Actor::DoAction ); +TypeAction a1(mType, std::string(ACTION_SHOW), &Actor::DoAction); +TypeAction a2(mType, std::string(ACTION_HIDE), &Actor::DoAction); /** * @brief Extract a given dimension from a Vector2 @@ -1373,43 +1373,45 @@ bool Actor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tra bool connected( true ); Actor* actor = static_cast< Actor* >( object ); // TypeRegistry guarantees that this is the correct type. - if( 0 == signalName.compare( SIGNAL_HOVERED ) ) + std::string_view name(signalName); + + if(name == SIGNAL_HOVERED) { actor->HoveredSignal().Connect( tracker, functor ); } - else if( 0 == signalName.compare( SIGNAL_WHEEL_EVENT ) ) + else if(signalName == SIGNAL_WHEEL_EVENT) { actor->WheelEventSignal().Connect( tracker, functor ); } - else if( 0 == signalName.compare( SIGNAL_ON_SCENE ) ) + else if(name == SIGNAL_ON_SCENE) { actor->OnSceneSignal().Connect( tracker, functor ); } - else if( 0 == signalName.compare( SIGNAL_OFF_SCENE ) ) + else if(name == SIGNAL_OFF_SCENE) { actor->OffSceneSignal().Connect( tracker, functor ); } - else if( 0 == signalName.compare( SIGNAL_ON_RELAYOUT ) ) + else if(name == SIGNAL_ON_RELAYOUT) { actor->OnRelayoutSignal().Connect( tracker, functor ); } - else if( 0 == signalName.compare( SIGNAL_TOUCHED ) ) + else if(name == SIGNAL_TOUCHED) { actor->TouchedSignal().Connect( tracker, functor ); } - else if( 0 == signalName.compare( SIGNAL_VISIBILITY_CHANGED ) ) + else if(name == SIGNAL_VISIBILITY_CHANGED) { actor->VisibilityChangedSignal().Connect( tracker, functor ); } - else if( 0 == signalName.compare( SIGNAL_LAYOUT_DIRECTION_CHANGED ) ) + else if(name == SIGNAL_LAYOUT_DIRECTION_CHANGED) { actor->LayoutDirectionChangedSignal().Connect( tracker, functor ); } - else if( 0 == signalName.compare( SIGNAL_CHILD_ADDED ) ) + else if(name == SIGNAL_CHILD_ADDED) { actor->ChildAddedSignal().Connect( tracker, functor ); } - else if( 0 == signalName.compare( SIGNAL_CHILD_REMOVED ) ) + else if(name == SIGNAL_CHILD_REMOVED) { actor->ChildRemovedSignal().Connect( tracker, functor ); } @@ -1870,12 +1872,13 @@ bool Actor::DoAction( BaseObject* object, const std::string& actionName, const P if( actor ) { - if( 0 == actionName.compare( ACTION_SHOW ) ) + std::string_view name(actionName); + if(name == ACTION_SHOW) { actor->SetVisible( true ); done = true; } - else if( 0 == actionName.compare( ACTION_HIDE ) ) + else if(name == ACTION_HIDE) { actor->SetVisible( false ); done = true; diff --git a/dali/internal/event/actors/layer-impl.cpp b/dali/internal/event/actors/layer-impl.cpp index dfb3011..d164abb 100644 --- a/dali/internal/event/actors/layer-impl.cpp +++ b/dali/internal/event/actors/layer-impl.cpp @@ -67,10 +67,10 @@ DALI_PROPERTY_TABLE_END( DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX, LayerDefaul // Actions -const char* const ACTION_RAISE = "raise"; -const char* const ACTION_LOWER = "lower"; -const char* const ACTION_RAISE_TO_TOP = "raiseToTop"; -const char* const ACTION_LOWER_TO_BOTTOM = "lowerToBottom"; +static constexpr std::string_view ACTION_RAISE = "raise"; +static constexpr std::string_view ACTION_LOWER = "lower"; +static constexpr std::string_view ACTION_RAISE_TO_TOP = "raiseToTop"; +static constexpr std::string_view ACTION_LOWER_TO_BOTTOM = "lowerToBottom"; BaseHandle Create() { @@ -79,10 +79,10 @@ BaseHandle Create() TypeRegistration mType( typeid( Dali::Layer ), typeid( Dali::Actor ), Create, LayerDefaultProperties ); -TypeAction a1( mType, ACTION_RAISE, &Layer::DoAction ); -TypeAction a2( mType, ACTION_LOWER, &Layer::DoAction ); -TypeAction a3( mType, ACTION_RAISE_TO_TOP, &Layer::DoAction ); -TypeAction a4( mType, ACTION_LOWER_TO_BOTTOM, &Layer::DoAction ); +TypeAction a1(mType, std::string(ACTION_RAISE), &Layer::DoAction); +TypeAction a2(mType, std::string(ACTION_LOWER), &Layer::DoAction); +TypeAction a3(mType, std::string(ACTION_RAISE_TO_TOP), &Layer::DoAction); +TypeAction a4(mType, std::string(ACTION_LOWER_TO_BOTTOM), &Layer::DoAction); } // unnamed namespace @@ -507,22 +507,24 @@ bool Layer::DoAction( BaseObject* object, const std::string& actionName, const P if( layer ) { - if( 0 == actionName.compare( ACTION_RAISE ) ) + std::string_view name(actionName); + + if(name == ACTION_RAISE) { layer->Raise(); done = true; } - else if( 0 == actionName.compare( ACTION_LOWER ) ) + else if(name == ACTION_LOWER) { layer->Lower(); done = true; } - else if( 0 == actionName.compare( ACTION_RAISE_TO_TOP ) ) + else if(name == ACTION_RAISE_TO_TOP) { layer->RaiseToTop(); done = true; } - else if( 0 == actionName.compare( ACTION_LOWER_TO_BOTTOM ) ) + else if(name == ACTION_LOWER_TO_BOTTOM) { layer->LowerToBottom(); done = true; diff --git a/dali/internal/event/animation/animation-impl.cpp b/dali/internal/event/animation/animation-impl.cpp index 0a05d70..088a719 100644 --- a/dali/internal/event/animation/animation-impl.cpp +++ b/dali/internal/event/animation/animation-impl.cpp @@ -56,13 +56,13 @@ namespace // Signals -const char* const SIGNAL_FINISHED = "finished"; +static constexpr std::string_view SIGNAL_FINISHED = "finished"; // Actions -const char* const ACTION_PLAY = "play"; -const char* const ACTION_STOP = "stop"; -const char* const ACTION_PAUSE = "pause"; +static constexpr std::string_view ACTION_PLAY = "play"; +static constexpr std::string_view ACTION_STOP = "stop"; +static constexpr std::string_view ACTION_PAUSE = "pause"; BaseHandle Create() { @@ -71,11 +71,11 @@ BaseHandle Create() TypeRegistration mType( typeid( Dali::Animation ), typeid( Dali::BaseHandle ), Create ); -SignalConnectorType signalConnector1( mType, SIGNAL_FINISHED, &Animation::DoConnectSignal ); +SignalConnectorType signalConnector1(mType, std::string(SIGNAL_FINISHED), &Animation::DoConnectSignal); -TypeAction action1( mType, ACTION_PLAY, &Animation::DoAction ); -TypeAction action2( mType, ACTION_STOP, &Animation::DoAction ); -TypeAction action3( mType, ACTION_PAUSE, &Animation::DoAction ); +TypeAction action1(mType, std::string(ACTION_PLAY), &Animation::DoAction); +TypeAction action2(mType, std::string(ACTION_STOP), &Animation::DoAction); +TypeAction action3(mType, std::string(ACTION_PAUSE), &Animation::DoAction); const Dali::Animation::EndAction DEFAULT_END_ACTION( Dali::Animation::BAKE ); const Dali::Animation::EndAction DEFAULT_DISCONNECT_ACTION( Dali::Animation::BAKE_FINAL ); @@ -860,7 +860,7 @@ bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* bool connected( false ); Animation* animation = static_cast< Animation* >(object); // TypeRegistry guarantees that this is the correct type. - if( 0 == signalName.compare( SIGNAL_FINISHED ) ) + if(SIGNAL_FINISHED == signalName) { animation->FinishedSignal().Connect( tracker, functor ); connected = true; @@ -951,7 +951,9 @@ bool Animation::DoAction( BaseObject* object, const std::string& actionName, con if( animation ) { - if( 0 == actionName.compare( ACTION_PLAY ) ) + std::string_view name(actionName); + + if(name == ACTION_PLAY) { if( Property::Value* value = attributes.Find("duration", Property::FLOAT) ) { @@ -961,12 +963,12 @@ bool Animation::DoAction( BaseObject* object, const std::string& actionName, con animation->Play(); done = true; } - else if( 0 == actionName.compare( ACTION_STOP ) ) + else if(name == ACTION_STOP) { animation->Stop(); done = true; } - else if( 0 == actionName.compare( ACTION_PAUSE ) ) + else if(name == ACTION_PAUSE) { animation->Pause(); done = true; diff --git a/dali/internal/event/common/stage-impl.cpp b/dali/internal/event/common/stage-impl.cpp index 87c2d37..804008f 100644 --- a/dali/internal/event/common/stage-impl.cpp +++ b/dali/internal/event/common/stage-impl.cpp @@ -62,25 +62,25 @@ namespace // Signals -const char* const SIGNAL_KEY_EVENT = "keyEvent"; -const char* const SIGNAL_KEY_EVENT_GENERATED = "keyEventGenerated"; -const char* const SIGNAL_EVENT_PROCESSING_FINISHED = "eventProcessingFinished"; -const char* const SIGNAL_TOUCHED = "touched"; -const char* const SIGNAL_WHEEL_EVENT = "wheelEvent"; -const char* const SIGNAL_CONTEXT_LOST = "contextLost"; -const char* const SIGNAL_CONTEXT_REGAINED = "contextRegained"; -const char* const SIGNAL_SCENE_CREATED = "sceneCreated"; +static constexpr std::string_view SIGNAL_KEY_EVENT = "keyEvent"; +static constexpr std::string_view SIGNAL_KEY_EVENT_GENERATED = "keyEventGenerated"; +static constexpr std::string_view SIGNAL_EVENT_PROCESSING_FINISHED = "eventProcessingFinished"; +static constexpr std::string_view SIGNAL_TOUCHED = "touched"; +static constexpr std::string_view SIGNAL_WHEEL_EVENT = "wheelEvent"; +static constexpr std::string_view SIGNAL_CONTEXT_LOST = "contextLost"; +static constexpr std::string_view SIGNAL_CONTEXT_REGAINED = "contextRegained"; +static constexpr std::string_view SIGNAL_SCENE_CREATED = "sceneCreated"; TypeRegistration mType( typeid(Dali::Stage), typeid(Dali::BaseHandle), nullptr ); -SignalConnectorType signalConnector1( mType, SIGNAL_KEY_EVENT, &Stage::DoConnectSignal ); -SignalConnectorType signalConnector2( mType, SIGNAL_EVENT_PROCESSING_FINISHED, &Stage::DoConnectSignal ); -SignalConnectorType signalConnector4( mType, SIGNAL_WHEEL_EVENT, &Stage::DoConnectSignal ); -SignalConnectorType signalConnector5( mType, SIGNAL_CONTEXT_LOST, &Stage::DoConnectSignal ); -SignalConnectorType signalConnector6( mType, SIGNAL_CONTEXT_REGAINED, &Stage::DoConnectSignal ); -SignalConnectorType signalConnector7( mType, SIGNAL_SCENE_CREATED, &Stage::DoConnectSignal ); -SignalConnectorType signalConnector8( mType, SIGNAL_KEY_EVENT_GENERATED, &Stage::DoConnectSignal ); -SignalConnectorType signalConnector9( mType, SIGNAL_TOUCHED, &Stage::DoConnectSignal ); +SignalConnectorType signalConnector1(mType, std::string(SIGNAL_KEY_EVENT), &Stage::DoConnectSignal); +SignalConnectorType signalConnector2(mType, std::string(SIGNAL_EVENT_PROCESSING_FINISHED), &Stage::DoConnectSignal); +SignalConnectorType signalConnector4(mType, std::string(SIGNAL_WHEEL_EVENT), &Stage::DoConnectSignal); +SignalConnectorType signalConnector5(mType, std::string(SIGNAL_CONTEXT_LOST), &Stage::DoConnectSignal); +SignalConnectorType signalConnector6(mType, std::string(SIGNAL_CONTEXT_REGAINED), &Stage::DoConnectSignal); +SignalConnectorType signalConnector7(mType, std::string(SIGNAL_SCENE_CREATED), &Stage::DoConnectSignal); +SignalConnectorType signalConnector8(mType, std::string(SIGNAL_KEY_EVENT_GENERATED), &Stage::DoConnectSignal); +SignalConnectorType signalConnector9(mType, std::string(SIGNAL_TOUCHED), &Stage::DoConnectSignal); } // unnamed namespace @@ -218,36 +218,37 @@ bool Stage::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tra { bool connected( true ); Stage* stage = static_cast< Stage* >(object); // TypeRegistry guarantees that this is the correct type. + std::string_view name(signalName); - if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) ) + if(name == SIGNAL_KEY_EVENT) { stage->KeyEventSignal().Connect( tracker, functor ); } - else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT_GENERATED ) ) + else if(name == SIGNAL_KEY_EVENT_GENERATED) { stage->KeyEventGeneratedSignal().Connect( tracker, functor ); } - else if( 0 == strcmp( signalName.c_str(), SIGNAL_EVENT_PROCESSING_FINISHED ) ) + else if(name == SIGNAL_EVENT_PROCESSING_FINISHED) { stage->EventProcessingFinishedSignal().Connect( tracker, functor ); } - else if( 0 == strcmp( signalName.c_str(), SIGNAL_TOUCHED ) ) + else if(name == SIGNAL_TOUCHED) { stage->TouchedSignal().Connect( tracker, functor ); } - else if( 0 == strcmp( signalName.c_str(), SIGNAL_WHEEL_EVENT ) ) + else if(name == SIGNAL_WHEEL_EVENT) { stage->WheelEventSignal().Connect( tracker, functor ); } - else if( 0 == strcmp( signalName.c_str(), SIGNAL_CONTEXT_LOST ) ) + else if(name == SIGNAL_CONTEXT_LOST) { stage->ContextLostSignal().Connect( tracker, functor ); } - else if( 0 == strcmp( signalName.c_str(), SIGNAL_CONTEXT_REGAINED ) ) + else if(name == SIGNAL_CONTEXT_REGAINED) { stage->ContextRegainedSignal().Connect( tracker, functor ); } - else if( 0 == strcmp( signalName.c_str(), SIGNAL_SCENE_CREATED ) ) + else if(name == SIGNAL_SCENE_CREATED) { stage->SceneCreatedSignal().Connect( tracker, functor ); } -- 2.7.4