1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-01-19 03:57:14 +01:00

Further optimize instance retrieval.

More risky changes but the current constraints should allow it.
This commit is contained in:
Sandu Liviu Catalin 2021-01-30 19:59:34 +02:00
parent b0bbb05631
commit bb991181de
2 changed files with 5 additions and 4 deletions

View File

@ -90,7 +90,7 @@ public:
sq_push(v, -2); sq_push(v, -2);
sq_rawset(v, -4); sq_rawset(v, -4);
} }
sq_pushstring(v, className.c_str(), -1); sq_pushstring(v, className.c_str(), static_cast<SQInteger>(className.size()));
auto** ud = reinterpret_cast<ClassData<C>**>(sq_newuserdata(v, sizeof(ClassData<C>*))); auto** ud = reinterpret_cast<ClassData<C>**>(sq_newuserdata(v, sizeof(ClassData<C>*)));
*ud = new ClassData<C>; *ud = new ClassData<C>;
sq_setreleasehook(v, -1, &cleanup_hook); sq_setreleasehook(v, -1, &cleanup_hook);

View File

@ -237,16 +237,17 @@ public:
} }
static C* GetInstance(HSQUIRRELVM vm, SQInteger idx, bool nullAllowed = false) { static C* GetInstance(HSQUIRRELVM vm, SQInteger idx, bool nullAllowed = false) {
AbstractStaticClassData* classType = nullptr; //AbstractStaticClassData* classType = nullptr;
AbstractStaticClassData* classType = StaticClassTypeTag<C>::Get();
std::pair<C*, SharedPtr<std::unordered_map<C*, HSQOBJECT>> >* instance = nullptr; std::pair<C*, SharedPtr<std::unordered_map<C*, HSQOBJECT>> >* instance = nullptr;
if (hasClassData(vm)) /* type checking only done if the value has type data else it may be enum */ //if (hasClassData(vm)) /* type checking only done if the value has type data else it may be enum */
if (classType!=nullptr) /* type checking only done if the value has type data else it may be enum */
{ {
if (nullAllowed && sq_gettype(vm, idx) == OT_NULL) { if (nullAllowed && sq_gettype(vm, idx) == OT_NULL) {
return nullptr; return nullptr;
} }
//classType = getStaticClassData().Lock().Get(); //classType = getStaticClassData().Lock().Get();
classType = StaticClassTypeTag<C>::Get();
#if !defined (SCRAT_NO_ERROR_CHECKING) #if !defined (SCRAT_NO_ERROR_CHECKING)
if (SQ_FAILED(sq_getinstanceup(vm, idx, (SQUserPointer*)&instance, classType))) { if (SQ_FAILED(sq_getinstanceup(vm, idx, (SQUserPointer*)&instance, classType))) {