From: Kimmo Hoikka Date: Thu, 25 Oct 2018 17:00:42 +0000 (+0100) Subject: Optimize type-info-impl and type-registry-impl X-Git-Tag: dali_1.3.48~6 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-core.git;a=commitdiff_plain;h=aee2350a06fac17860817a0e84ff97a4553dbbaa Optimize type-info-impl and type-registry-impl store base typeinfo pointer instead of resolving it every time a method is called. this is safe as type info cannot change after registration. store intrusive pointers to type-info-impl instead of handles as they are considerably cheaper In dali-demo startup reduced the count of calls: Before: TypeRegistry::GetTypeInfo 2409 TypeInfo::TypeInfo 3006 Change-Id: Idd53378ca15cc0f690597dd7a5855cb5986a6785 --- diff --git a/dali/internal/event/common/object-impl.cpp b/dali/internal/event/common/object-impl.cpp index 33c05da..3ea3729 100644 --- a/dali/internal/event/common/object-impl.cpp +++ b/dali/internal/event/common/object-impl.cpp @@ -954,10 +954,10 @@ const TypeInfo* Object::GetTypeInfo() const // This uses a dynamic_cast so can be quite expensive so we only really want to do it once // especially as the type-info does not change during the life-time of an application - Dali::TypeInfo typeInfoHandle = TypeRegistry::Get()->GetTypeInfo( this ); + TypeRegistry::TypeInfoPointer typeInfoHandle = TypeRegistry::Get()->GetTypeInfo( this ); if ( typeInfoHandle ) { - mTypeInfo = &GetImplementation( typeInfoHandle ); + mTypeInfo = typeInfoHandle.Get(); // just a raw pointer to use, ownership is kept } } @@ -1110,7 +1110,7 @@ Property::Index Object::RegisterSceneGraphProperty(const std::string& name, Prop void Object::RegisterAnimatableProperty( const TypeInfo& typeInfo, Property::Index index, - const Property::Value* value) const + const Property::Value* value ) const { // If the property is not a component of a base property, register the whole property itself. const std::string& propertyName = typeInfo.GetPropertyName( index ); diff --git a/dali/internal/event/common/type-info-impl.cpp b/dali/internal/event/common/type-info-impl.cpp index 19ff51d..65f63fc 100644 --- a/dali/internal/event/common/type-info-impl.cpp +++ b/dali/internal/event/common/type-info-impl.cpp @@ -32,6 +32,9 @@ using std::find_if; namespace Dali { +namespace Internal +{ + namespace { @@ -118,24 +121,56 @@ inline bool GetDefaultPropertyField( const Dali::PropertyDetails* propertyTable, return found; } -} // unnamed namespace +// static pointer value to mark that a base class address has not been resolved +// 0x01 is not a valid pointer but used here to differentiate from nullptr +// unfortunately it cannot be constexpr as C++ does not allow them to be initialised with reinterpret_cast +Internal::TypeInfo* const UNRESOLVED = reinterpret_cast( 0x1 ); -namespace Internal +/** + * Helper function to resolve and return the pointer to the base type info + * Not a member function to avoid having to #include additional headers and to make sure this gets inlined inside this cpp + * @param[in/out] baseType pointer to resolve and set + * @param[in] typeRegistry reference to the type registry + * @param[in] baseTypeName string name of the base type + * @return true is base type exists + */ +inline bool GetBaseType( Internal::TypeInfo*& baseType, TypeRegistry& typeRegistry, const std::string& baseTypeName ) { + // if greater than unresolved means we have a base type, null means no base + bool baseExists = ( baseType > UNRESOLVED ); + // base only needs to be resolved once + if( UNRESOLVED == baseType ) + { + TypeRegistry::TypeInfoPointer base = typeRegistry.GetTypeInfo( baseTypeName ); + if( base ) + { + baseType = base.Get(); // dont pass ownership, just return raw pointer + baseExists = true; + } + else + { + // no type info found so assuming no base as all type registration is done in startup for now + baseType = nullptr; + } + } + return baseExists; +} + +} // unnamed namespace TypeInfo::TypeInfo( const std::string &name, const std::string &baseTypeName, Dali::TypeInfo::CreateFunction creator, const Dali::PropertyDetails* defaultProperties, Property::Index defaultPropertyCount ) -: mTypeRegistry( *TypeRegistry::Get() ), - mTypeName(name), mBaseTypeName(baseTypeName), mCreate(creator), mDefaultProperties( defaultProperties ), - mDefaultPropertyCount( defaultPropertyCount ), mCSharpType(false) +: mTypeRegistry( *TypeRegistry::Get() ), mBaseType( UNRESOLVED ), + mTypeName( name ), mBaseTypeName( baseTypeName ), mCreate( creator ), mDefaultProperties( defaultProperties ), + mDefaultPropertyCount( defaultPropertyCount ), mCSharpType( false ) { DALI_ASSERT_ALWAYS(!name.empty() && "Type info construction must have a name"); DALI_ASSERT_ALWAYS(!baseTypeName.empty() && "Type info construction must have a base type name"); } TypeInfo::TypeInfo(const std::string &name, const std::string &baseTypeName, Dali::CSharpTypeInfo::CreateFunction creator) -: mTypeRegistry( *TypeRegistry::Get() ), - mTypeName(name), mBaseTypeName(baseTypeName), mCSharpCreate(creator), mCSharpType(true) +: mTypeRegistry( *TypeRegistry::Get() ), mBaseType( UNRESOLVED ), + mTypeName( name ), mBaseTypeName( baseTypeName ), mCSharpCreate( creator ), mCSharpType( true ) { DALI_ASSERT_ALWAYS(!name.empty() && "Type info construction must have a name"); DALI_ASSERT_ALWAYS(!baseTypeName.empty() && "Type info construction must have a base type name"); @@ -189,15 +224,10 @@ bool TypeInfo::DoActionTo(BaseObject *object, const std::string &actionName, con if( !done ) { - Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName ); - while( base ) + if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) { - done = GetImplementation(base).DoActionTo(object, actionName, properties); - if( done ) - { - break; - } - base = mTypeRegistry.GetTypeInfo( base.GetBaseName() ); + // call base type recursively + done = mBaseType->DoActionTo( object, actionName, properties ); } } @@ -216,6 +246,15 @@ bool TypeInfo::ConnectSignal( BaseObject* object, ConnectionTrackerInterface* co connected = (iter->second)( object, connectionTracker, signalName, functor ); } + if( !connected ) + { + if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) + { + // call base type recursively + connected = mBaseType->ConnectSignal( object, connectionTracker, signalName, functor ); + } + } + return connected; } @@ -238,11 +277,10 @@ size_t TypeInfo::GetActionCount() const { size_t count = mActions.size(); - Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName ); - while( base ) + if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) { - count += GetImplementation(base).mActions.size(); - base = mTypeRegistry.GetTypeInfo( base.GetBaseName() ); + // call base type recursively + count += mBaseType->GetActionCount(); } return count; @@ -251,29 +289,18 @@ size_t TypeInfo::GetActionCount() const std::string TypeInfo::GetActionName(size_t index) const { std::string name; + const size_t count = mActions.size(); - if( index < mActions.size() ) + if( index < count ) { name = mActions[index].first; } else { - size_t count = mActions.size(); - - Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName ); - while( base ) + if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) { - size_t baseCount = GetImplementation(base).mActions.size(); - - if( index < count + baseCount ) - { - name = GetImplementation(base).mActions[ index - count ].first; - break; - } - - count += baseCount; - - base = mTypeRegistry.GetTypeInfo( base.GetBaseName() ); + // call base type recursively + return mBaseType->GetActionName( index - count ); } } @@ -284,11 +311,10 @@ size_t TypeInfo::GetSignalCount() const { size_t count = mSignalConnectors.size(); - Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName ); - while( base ) + if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) { - count += GetImplementation(base).mSignalConnectors.size(); - base = mTypeRegistry.GetTypeInfo( base.GetBaseName() ); + // call base type recursively + count += mBaseType->GetSignalCount(); } return count; @@ -297,29 +323,18 @@ size_t TypeInfo::GetSignalCount() const std::string TypeInfo::GetSignalName(size_t index) const { std::string name; + const size_t count = mSignalConnectors.size(); - if( index < mSignalConnectors.size() ) + if( index < count ) { name = mSignalConnectors[index].first; } else { - size_t count = mSignalConnectors.size(); - - Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName ); - while( base ) + if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) { - size_t baseCount = GetImplementation(base).mSignalConnectors.size(); - - if( index < count + baseCount ) - { - name = GetImplementation(base).mSignalConnectors[ index - count ].first; - break; - } - - count += baseCount; - - base = mTypeRegistry.GetTypeInfo( base.GetBaseName() ); + // call base type recursively + return mBaseType->GetSignalName( index - count ); } } @@ -338,11 +353,10 @@ void TypeInfo::GetPropertyIndices( Property::IndexContainer& indices ) const } } - Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName ); - if ( base ) + if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) { - const TypeInfo& baseImpl( GetImplementation( base ) ); - baseImpl.GetPropertyIndices( indices ); + // call base type recursively + mBaseType->GetPropertyIndices( indices ); } AppendProperties( indices, mRegisteredProperties ); @@ -350,11 +364,10 @@ void TypeInfo::GetPropertyIndices( Property::IndexContainer& indices ) const void TypeInfo::GetChildPropertyIndices( Property::IndexContainer& indices ) const { - Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName ); - if ( base ) + if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) { - const TypeInfo& baseImpl( GetImplementation( base ) ); - baseImpl.GetChildPropertyIndices( indices ); + // call base type recursively + mBaseType->GetChildPropertyIndices( indices ); } AppendProperties( indices, mRegisteredChildProperties ); @@ -385,10 +398,10 @@ const std::string& TypeInfo::GetRegisteredPropertyName( Property::Index index ) { return iter->second.name; } - Dali::TypeInfo base = TypeRegistry::Get()->GetTypeInfo( mBaseTypeName ); - if ( base ) + if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) { - return GetImplementation(base).GetRegisteredPropertyName( index ); + // call base type recursively + return mBaseType->GetRegisteredPropertyName( index ); } static std::string empty; return empty; @@ -418,10 +431,10 @@ std::string TypeInfo::GetPropertyName( Property::Index index ) const // if not our property, go to parent if( propertyName.empty() ) { - Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName ); - if ( base ) + if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) { - return GetImplementation(base).GetPropertyName( index ); + // call base type recursively + return mBaseType->GetPropertyName( index ); } } @@ -598,12 +611,10 @@ uint32_t TypeInfo::GetPropertyCount() const { uint32_t count = mDefaultPropertyCount + static_cast( mRegisteredProperties.size() ); - Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName ); - while ( base ) + if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) { - const TypeInfo& baseImpl( GetImplementation(base) ); - count += baseImpl.mDefaultPropertyCount + static_cast( baseImpl.mRegisteredProperties.size() ); - base = mTypeRegistry.GetTypeInfo( baseImpl.mBaseTypeName ); + // call base type recursively + count += mBaseType->GetPropertyCount(); } return count; @@ -636,13 +647,10 @@ Property::Index TypeInfo::GetPropertyIndex( const std::string& name ) const { index = iter->first; } - else + else if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) { - Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName ); - if ( base ) - { - index = GetImplementation(base).GetPropertyIndex( name ); - } + // call base type recursively + index = mBaseType->GetPropertyIndex( name ); } } @@ -660,13 +668,10 @@ Property::Index TypeInfo::GetBasePropertyIndex( Property::Index index ) const { basePropertyIndex = iter->second.basePropertyIndex; } - else + else if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) { - Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName ); - if ( base ) - { - basePropertyIndex = GetImplementation(base).GetBasePropertyIndex( index ); - } + // call base type recursively + basePropertyIndex = mBaseType->GetBasePropertyIndex( index ); } return basePropertyIndex; @@ -683,13 +688,10 @@ int TypeInfo::GetComponentIndex( Property::Index index ) const { componentIndex = iter->second.componentIndex; } - else + else if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) { - Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName ); - if ( base ) - { - componentIndex = GetImplementation(base).GetComponentIndex( index ); - } + // call base type recursively + componentIndex = mBaseType->GetComponentIndex( index ); } return componentIndex; @@ -707,13 +709,10 @@ Property::Index TypeInfo::GetChildPropertyIndex( const std::string& name ) const { index = iter->first; } - else + else if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) { - Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName ); - if ( base ) - { - index = GetImplementation(base).GetChildPropertyIndex( name ); - } + // call base type recursively + index = mBaseType->GetChildPropertyIndex( name ); } return index; @@ -729,10 +728,10 @@ const std::string& TypeInfo::GetChildPropertyName( Property::Index index ) const return iter->second.name; } - Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName ); - if ( base ) + if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) { - return GetImplementation(base).GetChildPropertyName( index ); + // call base type recursively + return mBaseType->GetChildPropertyName( index ); } DALI_LOG_ERROR( "Property index %d not found\n", index ); @@ -752,17 +751,14 @@ Property::Type TypeInfo::GetChildPropertyType( Property::Index index ) const { type = iter->second.type; } + else if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) + { + // call base type recursively + type = mBaseType->GetChildPropertyType( index ); + } else { - Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName ); - if ( base ) - { - type = GetImplementation(base).GetChildPropertyType( index ); - } - else - { - DALI_LOG_ERROR( "Property index %d not found\n", index ); - } + DALI_LOG_ERROR( "Property index %d not found\n", index ); } return type; @@ -797,10 +793,10 @@ bool TypeInfo::IsPropertyWritable( Property::Index index ) const // if not found, continue to base if( !found ) { - Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName ); - if ( base ) + if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) { - writable = GetImplementation(base).IsPropertyWritable( index ); + // call base type recursively + writable = mBaseType->IsPropertyWritable( index ); } else { @@ -836,10 +832,10 @@ bool TypeInfo::IsPropertyAnimatable( Property::Index index ) const // if not found, continue to base if( !found ) { - Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName ); - if ( base ) + if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) { - animatable = GetImplementation(base).IsPropertyAnimatable( index ); + // call base type recursively + animatable = mBaseType->IsPropertyAnimatable( index ); } else { @@ -875,10 +871,10 @@ bool TypeInfo::IsPropertyAConstraintInput( Property::Index index ) const // if not found, continue to base if( !found ) { - Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName ); - if ( base ) + if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) { - constraintInput = GetImplementation(base).IsPropertyAConstraintInput( index ); + // call base type recursively + constraintInput = mBaseType->IsPropertyAConstraintInput( index ); } else { @@ -923,10 +919,10 @@ Property::Type TypeInfo::GetPropertyType( Property::Index index ) const if( !found ) { - Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName ); - if ( base ) + if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) { - type = GetImplementation(base).GetPropertyType( index ); + // call base type recursively + type = mBaseType->GetPropertyType( index ); } else { @@ -941,7 +937,7 @@ Property::Value TypeInfo::GetPropertyDefaultValue( Property::Index index ) const { PropertyDefaultValueContainer::const_iterator iter = find_if( mPropertyDefaultValues.begin(), mPropertyDefaultValues.end(), PairFinder< Property::Index, PropertyDefaultValuePair >( index ) ); - if( iter != mPropertyDefaultValues.end() ) + if( iter != mPropertyDefaultValues.end() ) { return iter->second; } @@ -972,17 +968,14 @@ void TypeInfo::SetProperty( BaseObject *object, Property::Index index, const Pro } } } + else if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) + { + // call base type recursively + mBaseType->SetProperty( object, index, value ); + } else { - Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName ); - if ( base ) - { - GetImplementation(base).SetProperty( object, index, value ); - } - else - { - DALI_LOG_ERROR( "Property index %d not found\n", index ); - } + DALI_LOG_ERROR( "Property index %d not found\n", index ); } } @@ -1004,17 +997,14 @@ void TypeInfo::SetProperty( BaseObject *object, const std::string& name, const P iter->second.setFunc( object, iter->first, value ); } } + else if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) + { + // call base type recursively + mBaseType->SetProperty( object, name, value ); + } else { - Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName ); - if ( base ) - { - GetImplementation(base).SetProperty( object, name, value ); - } - else - { - DALI_LOG_ERROR( "Property %s not found", name.c_str() ); - } + DALI_LOG_ERROR( "Property %s not found", name.c_str() ); } } @@ -1041,10 +1031,10 @@ Property::Value TypeInfo::GetProperty( const BaseObject *object, Property::Index } } - Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName ); - if ( base ) + if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) { - return GetImplementation( base ).GetProperty( object, index ); + // call base type recursively + return mBaseType->GetProperty( object, index ); } DALI_LOG_ERROR( "Property index %d not found\n", index ); @@ -1075,10 +1065,10 @@ Property::Value TypeInfo::GetProperty( const BaseObject *object, const std::stri } } - Dali::TypeInfo base = mTypeRegistry.GetTypeInfo( mBaseTypeName ); - if ( base ) + if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) ) { - return GetImplementation( base ).GetProperty( object, name ); + // call base type recursively + return mBaseType->GetProperty( object, name ); } DALI_LOG_ERROR( "Property %s not found", name.c_str() ); diff --git a/dali/internal/event/common/type-info-impl.h b/dali/internal/event/common/type-info-impl.h index 06fd0a1..54cfe22 100644 --- a/dali/internal/event/common/type-info-impl.h +++ b/dali/internal/event/common/type-info-impl.h @@ -405,6 +405,7 @@ private: private: TypeRegistry& mTypeRegistry; + mutable Internal::TypeInfo* mBaseType; // allow changing from const methods, initialised inside constructor std::string mTypeName; std::string mBaseTypeName; union diff --git a/dali/internal/event/common/type-registry-impl.cpp b/dali/internal/event/common/type-registry-impl.cpp index 20a69b8..d380f83 100644 --- a/dali/internal/event/common/type-registry-impl.cpp +++ b/dali/internal/event/common/type-registry-impl.cpp @@ -61,23 +61,23 @@ TypeRegistry::~TypeRegistry() mRegistryLut.clear(); } -Dali::TypeInfo TypeRegistry::GetTypeInfo( const std::string& uniqueTypeName ) +TypeRegistry::TypeInfoPointer TypeRegistry::GetTypeInfo( const std::string& uniqueTypeName ) { for( auto&& iter : mRegistryLut ) { // Note! mRegistryLut contains Dali::TypeInfo handles, so cannot call GetTypeName() // as it calls us back resulting in infinite loop (GetTypeName is in BaseHandle part) - if( GetImplementation( iter ).GetName() == uniqueTypeName ) + if( iter->GetName() == uniqueTypeName ) { return iter; } } DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Cannot find requested type '%s'\n", uniqueTypeName.c_str() ); - return Dali::TypeInfo(); + return TypeRegistry::TypeInfoPointer(); } -Dali::TypeInfo TypeRegistry::GetTypeInfo( const std::type_info& registerType ) +TypeRegistry::TypeInfoPointer TypeRegistry::GetTypeInfo( const std::type_info& registerType ) { std::string typeName = DemangleClassName( registerType.name() ); @@ -95,7 +95,7 @@ std::string TypeRegistry::GetTypeName( size_t index ) const if( index < mRegistryLut.size() ) { - name = GetImplementation( mRegistryLut[ index ] ).GetName(); + name = mRegistryLut[ index ]->GetName(); } return name; @@ -127,7 +127,7 @@ std::string TypeRegistry::Register( const std::string& uniqueTypeName, const std // check for duplicates using uniqueTypeName for( auto&& iter : mRegistryLut ) { - if( GetImplementation( iter ).GetName() == uniqueTypeName ) + if( iter->GetName() == uniqueTypeName ) { DALI_LOG_WARNING( "Duplicate name in TypeRegistry for '%s'\n", + uniqueTypeName.c_str() ); DALI_ASSERT_ALWAYS( !"Duplicate type name in Type Registration" ); @@ -135,7 +135,7 @@ std::string TypeRegistry::Register( const std::string& uniqueTypeName, const std } } - mRegistryLut.push_back( Dali::TypeInfo( new Internal::TypeInfo( uniqueTypeName, baseTypeName, createInstance, defaultProperties, defaultPropertyCount ) ) ); + mRegistryLut.push_back( TypeRegistry::TypeInfoPointer( new Internal::TypeInfo( uniqueTypeName, baseTypeName, createInstance, defaultProperties, defaultPropertyCount ) ) ); DALI_LOG_INFO( gLogFilter, Debug::Concise, "Type Registration %s(%s)\n", uniqueTypeName.c_str(), baseTypeName.c_str() ); if( callCreateOnInit ) @@ -154,7 +154,7 @@ void TypeRegistry::Register( const std::string& uniqueTypeName, const std::type_ // check for duplicates using uniqueTypeName for( auto&& iter : mRegistryLut ) { - if( GetImplementation( iter ).GetName() == uniqueTypeName ) + if( iter->GetName() == uniqueTypeName ) { DALI_LOG_WARNING( "Duplicate name in TypeRegistry for '%s'\n", + uniqueTypeName.c_str() ); DALI_ASSERT_ALWAYS( !"Duplicate type name in Type Registration" ); @@ -162,7 +162,7 @@ void TypeRegistry::Register( const std::string& uniqueTypeName, const std::type_ } } - mRegistryLut.push_back( Dali::TypeInfo( new Internal::TypeInfo( uniqueTypeName, baseTypeName, createInstance ) ) ); + mRegistryLut.push_back( TypeRegistry::TypeInfoPointer( new Internal::TypeInfo( uniqueTypeName, baseTypeName, createInstance ) ) ); DALI_LOG_INFO( gLogFilter, Debug::Concise, "Type Registration %s(%s)\n", uniqueTypeName.c_str(), baseTypeName.c_str() ); } @@ -183,10 +183,9 @@ void TypeRegistry::RegisterSignal( TypeRegistration& typeRegistration, const std { for( auto&& iter : mRegistryLut ) { - auto&& impl = GetImplementation( iter ); - if( impl.GetName() == typeRegistration.RegisteredName() ) + if( iter->GetName() == typeRegistration.RegisteredName() ) { - impl.AddConnectorFunction( name, func ); + iter->AddConnectorFunction( name, func ); break; } } @@ -196,10 +195,9 @@ bool TypeRegistry::RegisterAction( TypeRegistration& typeRegistration, const std { for( auto&& iter : mRegistryLut ) { - auto&& impl = GetImplementation( iter ); - if( impl.GetName() == typeRegistration.RegisteredName() ) + if( iter->GetName() == typeRegistration.RegisteredName() ) { - impl.AddActionFunction( name, f ); + iter->AddActionFunction( name, f ); return true; } } @@ -210,10 +208,9 @@ bool TypeRegistry::RegisterProperty( TypeRegistration& typeRegistration, const s { for( auto&& iter : mRegistryLut ) { - auto&& impl = GetImplementation( iter ); - if( impl.GetName() == typeRegistration.RegisteredName() ) + if( iter->GetName() == typeRegistration.RegisteredName() ) { - impl.AddProperty( name, index, type, setFunc, getFunc ); + iter->AddProperty( name, index, type, setFunc, getFunc ); return true; } } @@ -225,10 +222,9 @@ bool TypeRegistry::RegisterProperty( const std::string& objectName, const std::s { for( auto&& iter : mRegistryLut ) { - auto&& impl = GetImplementation( iter ); - if( impl.GetName() == objectName ) + if( iter->GetName() == objectName ) { - impl.AddProperty( name, index, type, setFunc, getFunc ); + iter->AddProperty( name, index, type, setFunc, getFunc ); return true; } } @@ -241,10 +237,9 @@ bool TypeRegistry::RegisterAnimatableProperty( TypeRegistration& typeRegistratio { for( auto&& iter : mRegistryLut ) { - auto&& impl = GetImplementation( iter ); - if( impl.GetName() == typeRegistration.RegisteredName() ) + if( iter->GetName() == typeRegistration.RegisteredName() ) { - impl.AddAnimatableProperty( name, index, type ); + iter->AddAnimatableProperty( name, index, type ); return true; } } @@ -256,10 +251,9 @@ bool TypeRegistry::RegisterAnimatableProperty( TypeRegistration& typeRegistratio { for( auto&& iter : mRegistryLut ) { - auto&& impl = GetImplementation( iter ); - if( impl.GetName() == typeRegistration.RegisteredName() ) + if( iter->GetName() == typeRegistration.RegisteredName() ) { - impl.AddAnimatableProperty( name, index, value ); + iter->AddAnimatableProperty( name, index, value ); return true; } } @@ -271,10 +265,9 @@ bool TypeRegistry::RegisterAnimatablePropertyComponent( TypeRegistration& typeRe { for( auto&& iter : mRegistryLut ) { - auto&& impl = GetImplementation( iter ); - if( impl.GetName() == typeRegistration.RegisteredName() ) + if( iter->GetName() == typeRegistration.RegisteredName() ) { - impl.AddAnimatablePropertyComponent( name, index, baseIndex, componentIndex ); + iter->AddAnimatablePropertyComponent( name, index, baseIndex, componentIndex ); return true; } } @@ -286,10 +279,9 @@ bool TypeRegistry::RegisterChildProperty( const std::string& registeredType, con { for( auto&& iter : mRegistryLut ) { - auto&& impl = GetImplementation( iter ); - if( impl.GetName() == registeredType ) + if( iter->GetName() == registeredType ) { - impl.AddChildProperty( name, index, type ); + iter->AddChildProperty( name, index, type ); return true; } } @@ -306,15 +298,14 @@ bool TypeRegistry::DoActionTo( BaseObject * const object, const std::string& act { bool done = false; - Dali::TypeInfo type = GetTypeInfo( object ); + auto&& type = GetTypeInfo( object ); - auto&& impl = GetImplementation( type ); // DoActionTo recurses through base classes - done = impl.DoActionTo( object, actionName, properties ); + done = type->DoActionTo( object, actionName, properties ); if( !done ) { - DALI_LOG_WARNING("Type '%s' cannot do action '%s'\n", type.GetName().c_str(), actionName.c_str()); + DALI_LOG_WARNING("Type '%s' cannot do action '%s'\n", type->GetName().c_str(), actionName.c_str()); } return done; @@ -324,21 +315,14 @@ bool TypeRegistry::ConnectSignal( BaseObject* object, ConnectionTrackerInterface { bool connected( false ); - Dali::TypeInfo type = GetTypeInfo( object ); + auto&& type = GetTypeInfo( object ); - while( type ) - { - auto&& impl = GetImplementation( type ); - connected = impl.ConnectSignal( object, connectionTracker, signalName, functor ); - if( connected ) - { - break; - } - type = GetTypeInfo( impl.GetBaseName() ); - } + // Connect iterates through base classes + connected = type->ConnectSignal( object, connectionTracker, signalName, functor ); if( !connected ) { + DALI_LOG_WARNING("Type '%s' signal '%s' connection failed \n", type->GetName().c_str(), signalName.c_str()); // Ownership of functor was not passed to Dali::CallbackBase, so clean-up now delete functor; } @@ -346,14 +330,14 @@ bool TypeRegistry::ConnectSignal( BaseObject* object, ConnectionTrackerInterface return connected; } -Dali::TypeInfo TypeRegistry::GetTypeInfo(const Dali::BaseObject * const pBaseObject) +TypeRegistry::TypeInfoPointer TypeRegistry::GetTypeInfo(const Dali::BaseObject * const pBaseObject) { - Dali::TypeInfo type; + TypeInfoPointer type; // test for custom actor which has another indirection to get to the type hiearchy we're after const Dali::Internal::CustomActor * const pCustom = dynamic_cast(pBaseObject); - if(pCustom) + if( pCustom ) { const Dali::CustomActorImpl& custom = pCustom->GetImplementation(); type = GetTypeInfo( typeid( custom ) ); diff --git a/dali/internal/event/common/type-registry-impl.h b/dali/internal/event/common/type-registry-impl.h index 2368d57..8f72dd0 100644 --- a/dali/internal/event/common/type-registry-impl.h +++ b/dali/internal/event/common/type-registry-impl.h @@ -40,6 +40,10 @@ class PropertyDetails; class TypeRegistry : public Dali::BaseObject { public: + + // using intrusive pointer instead of handles internally as they are considerably cheaper + using TypeInfoPointer = IntrusivePtr; + /** * Get the TypeRegistry */ @@ -48,12 +52,12 @@ public: /** * @copydoc Dali::TypeRegistry::GetTypeInfo */ - Dali::TypeInfo GetTypeInfo( const std::string &uniqueTypeName ); + TypeInfoPointer GetTypeInfo( const std::string &uniqueTypeName ); /** * @copydoc Dali::TypeRegistry::GetTypeInfo */ - Dali::TypeInfo GetTypeInfo( const std::type_info& registerType ); + TypeInfoPointer GetTypeInfo( const std::type_info& registerType ); /** * @copydoc Dali::TypeRegistry::GetTypeNameCount @@ -222,7 +226,7 @@ public: * @param [in] pBaseObject Pointer to a BaseObject * @return TypeInfo for the BaseObject. */ - Dali::TypeInfo GetTypeInfo(const Dali::BaseObject * const pBaseObject); + TypeInfoPointer GetTypeInfo(const Dali::BaseObject * const pBaseObject); /** * Calls any type creation functions that have been flagged as initialization functions @@ -242,7 +246,7 @@ private: /* * Mapping from type name to TypeInfo */ - std::vector< Dali::TypeInfo > mRegistryLut; + std::vector< TypeInfoPointer > mRegistryLut; std::vector< Dali::TypeInfo::CreateFunction > mInitFunctions; diff --git a/dali/public-api/object/base-object.cpp b/dali/public-api/object/base-object.cpp index a464952..362bde2 100644 --- a/dali/public-api/object/base-object.cpp +++ b/dali/public-api/object/base-object.cpp @@ -73,10 +73,10 @@ const std::string& BaseObject::GetTypeName() const if( registry ) { - Dali::TypeInfo typeInfo = registry->GetTypeInfo(this); + Internal::TypeRegistry::TypeInfoPointer typeInfo = registry->GetTypeInfo(this); if( typeInfo ) { - return typeInfo.GetName(); + return typeInfo->GetName(); } } @@ -90,10 +90,10 @@ bool BaseObject::GetTypeInfo(Dali::TypeInfo& typeInfo) const { Dali::Internal::TypeRegistry* registry = Dali::Internal::TypeRegistry::Get(); - Dali::TypeInfo info = registry->GetTypeInfo(this); + Internal::TypeRegistry::TypeInfoPointer info = registry->GetTypeInfo(this); if(info) { - typeInfo = info; + typeInfo = Dali::TypeInfo( info.Get() ); return true; } else diff --git a/dali/public-api/object/type-registry.cpp b/dali/public-api/object/type-registry.cpp index 48a1c45..f3b1eea 100644 --- a/dali/public-api/object/type-registry.cpp +++ b/dali/public-api/object/type-registry.cpp @@ -54,12 +54,12 @@ TypeRegistry TypeRegistry::Get() Dali::TypeInfo TypeRegistry::GetTypeInfo( const std::string &uniqueTypeName ) { - return GetImplementation(*this).GetTypeInfo( uniqueTypeName ); + return Dali::TypeInfo( GetImplementation(*this).GetTypeInfo( uniqueTypeName ).Get() ); } Dali::TypeInfo TypeRegistry::GetTypeInfo( const std::type_info& registerType ) { - return GetImplementation(*this).GetTypeInfo( registerType ); + return Dali::TypeInfo( GetImplementation(*this).GetTypeInfo( registerType ).Get() ); } size_t TypeRegistry::GetTypeNameCount() const