UI: IocContainer: Microoptimize

This commit is contained in:
Nodir Temirkhodjaev 2024-01-18 12:44:21 +03:00
parent 9a74a8225b
commit 8875a55015
2 changed files with 17 additions and 18 deletions

View File

@ -56,18 +56,20 @@ void IocContainer::autoDeleteAll()
}
}
void IocContainer::setUp(int typeId)
IocService *IocContainer::setUp(int typeId)
{
const quint8 flags = m_objectFlags[typeId];
if ((flags & (IsService | WasSetUp)) != IsService)
return;
IocService *obj = resolveService(typeId);
const quint8 flags = m_objectFlags[typeId];
if ((flags & (IsService | WasSetUp)) == IsService) {
m_objectFlags[typeId] = (flags | WasSetUp);
IocService *obj = resolveService(typeId);
obj->setUp();
}
return obj;
}
void IocContainer::tearDown(int typeId)
{
const quint8 flags = m_objectFlags[typeId];

View File

@ -66,17 +66,16 @@ public:
return static_cast<T *>(resolveService(getTypeId<T>()));
}
void setUpAll();
void tearDownAll();
void autoDeleteAll();
template<class T>
inline constexpr T *setUpDependency()
{
setUp(getTypeId<T>());
return resolve<T>();
return static_cast<T *>(setUp(getTypeId<T>()));
}
void setUpAll();
void tearDownAll();
void autoDeleteAll();
bool pinToThread();
inline static IocContainer *getPinned()
@ -101,7 +100,7 @@ private:
return static_cast<IocService *>(resolveObject(typeId));
}
void setUp(int typeId);
IocService *setUp(int typeId);
void tearDown(int typeId);
void autoDelete(int typeId);
@ -124,9 +123,7 @@ constexpr auto IoCPinned = IocContainer::getPinned;
template<class T>
inline static T *IoC()
{
const IocContainer *container = IoCPinned();
Q_ASSERT(container);
return container->resolve<T>();
return IoCPinned()->resolve<T>();
}
#endif // IOCCONTAINER_H