mirror of
https://github.com/tnodir/fort
synced 2024-11-15 09:25:40 +00:00
UI: IocContainer: Just use arrays.
This commit is contained in:
parent
bad1b2fafa
commit
7d1e1f6f4d
@ -17,9 +17,12 @@ void IocContainer::setObject(int typeId, IocObject *obj, quint8 flags)
|
||||
{
|
||||
const int newSize = typeId + 1;
|
||||
if (newSize > m_size) {
|
||||
if (Q_UNLIKELY(newSize > IOC_MAX_SIZE)) {
|
||||
qCritical() << "IoC Container size error";
|
||||
Q_UNREACHABLE();
|
||||
abort();
|
||||
}
|
||||
m_size = newSize;
|
||||
m_objects.resize(newSize);
|
||||
m_objectFlags.resize(newSize);
|
||||
}
|
||||
|
||||
m_objects[typeId] = obj;
|
||||
|
@ -2,7 +2,6 @@
|
||||
#define IOCCONTAINER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QVarLengthArray>
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <qt_windows.h>
|
||||
@ -11,7 +10,7 @@
|
||||
|
||||
using IocObject = void;
|
||||
|
||||
constexpr int IOC_DEFAULT_SIZE = 32;
|
||||
constexpr int IOC_MAX_SIZE = 32;
|
||||
|
||||
class IocContainer : public QObject
|
||||
{
|
||||
@ -97,7 +96,7 @@ public:
|
||||
private:
|
||||
void setObject(int typeId, IocObject *obj, quint8 flags = 0);
|
||||
|
||||
inline IocObject *resolveObject(int typeId) const { return m_objects.at(typeId); }
|
||||
inline IocObject *resolveObject(int typeId) const { return m_objects[typeId]; }
|
||||
inline IocService *resolveService(int typeId) const
|
||||
{
|
||||
return static_cast<IocService *>(resolveObject(typeId));
|
||||
@ -117,8 +116,8 @@ private:
|
||||
|
||||
int m_size = 0;
|
||||
|
||||
QVarLengthArray<IocObject *, IOC_DEFAULT_SIZE> m_objects;
|
||||
QVarLengthArray<quint8, IOC_DEFAULT_SIZE> m_objectFlags;
|
||||
quint8 m_objectFlags[IOC_MAX_SIZE] = {};
|
||||
IocObject *m_objects[IOC_MAX_SIZE] = {};
|
||||
};
|
||||
|
||||
template<class T>
|
||||
|
Loading…
Reference in New Issue
Block a user