mirror of
https://github.com/tnodir/fort
synced 2024-11-15 08:35:08 +00:00
UI: IocContainer: Microoptimize
This commit is contained in:
parent
9a74a8225b
commit
8875a55015
@ -56,16 +56,18 @@ 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;
|
|
||||||
|
|
||||||
m_objectFlags[typeId] = (flags | WasSetUp);
|
|
||||||
|
|
||||||
IocService *obj = resolveService(typeId);
|
IocService *obj = resolveService(typeId);
|
||||||
obj->setUp();
|
|
||||||
|
const quint8 flags = m_objectFlags[typeId];
|
||||||
|
if ((flags & (IsService | WasSetUp)) == IsService) {
|
||||||
|
m_objectFlags[typeId] = (flags | WasSetUp);
|
||||||
|
|
||||||
|
obj->setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IocContainer::tearDown(int typeId)
|
void IocContainer::tearDown(int typeId)
|
||||||
|
@ -66,17 +66,16 @@ public:
|
|||||||
return static_cast<T *>(resolveService(getTypeId<T>()));
|
return static_cast<T *>(resolveService(getTypeId<T>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void setUpAll();
|
|
||||||
void tearDownAll();
|
|
||||||
void autoDeleteAll();
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline constexpr T *setUpDependency()
|
inline constexpr T *setUpDependency()
|
||||||
{
|
{
|
||||||
setUp(getTypeId<T>());
|
return static_cast<T *>(setUp(getTypeId<T>()));
|
||||||
return resolve<T>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setUpAll();
|
||||||
|
void tearDownAll();
|
||||||
|
void autoDeleteAll();
|
||||||
|
|
||||||
bool pinToThread();
|
bool pinToThread();
|
||||||
|
|
||||||
inline static IocContainer *getPinned()
|
inline static IocContainer *getPinned()
|
||||||
@ -101,7 +100,7 @@ private:
|
|||||||
return static_cast<IocService *>(resolveObject(typeId));
|
return static_cast<IocService *>(resolveObject(typeId));
|
||||||
}
|
}
|
||||||
|
|
||||||
void setUp(int typeId);
|
IocService *setUp(int typeId);
|
||||||
void tearDown(int typeId);
|
void tearDown(int typeId);
|
||||||
void autoDelete(int typeId);
|
void autoDelete(int typeId);
|
||||||
|
|
||||||
@ -124,9 +123,7 @@ constexpr auto IoCPinned = IocContainer::getPinned;
|
|||||||
template<class T>
|
template<class T>
|
||||||
inline static T *IoC()
|
inline static T *IoC()
|
||||||
{
|
{
|
||||||
const IocContainer *container = IoCPinned();
|
return IoCPinned()->resolve<T>();
|
||||||
Q_ASSERT(container);
|
|
||||||
return container->resolve<T>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // IOCCONTAINER_H
|
#endif // IOCCONTAINER_H
|
||||||
|
Loading…
Reference in New Issue
Block a user