1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-02-22 20:57:12 +01:00

Use optimized type identification.

This commit is contained in:
Sandu Liviu Catalin 2021-03-20 11:49:58 +02:00
parent f11622177e
commit 86e070d61c

View File

@ -318,7 +318,15 @@ SQInteger PopStackInteger(HSQUIRRELVM vm, SQInteger idx)
} }
case OT_INSTANCE: case OT_INSTANCE:
{ {
// Attempt to treat the value as a signed long instance SQUserPointer tag;
// Attempt to retrieve the type tag
if (SQ_FAILED(sq_gettypetag(vm, -1, &tag)))
{
break;
}
// Is the instance SLongInt? (signed long)
else if (static_cast< AbstractStaticClassData * >(tag) == StaticClassTypeTag< SLongInt >::Get())
{
try try
{ {
return ConvTo< SQInteger >::From(Var< const SLongInt & >(vm, idx).value.GetNum()); return ConvTo< SQInteger >::From(Var< const SLongInt & >(vm, idx).value.GetNum());
@ -327,7 +335,10 @@ SQInteger PopStackInteger(HSQUIRRELVM vm, SQInteger idx)
{ {
// Just ignore it... // Just ignore it...
} }
// Attempt to treat the value as a unsigned long instance }
// Is the instance ULongInt? (unsigned long)
else if (static_cast< AbstractStaticClassData * >(tag) == StaticClassTypeTag< ULongInt >::Get())
{
try try
{ {
return ConvTo< SQInteger >::From(Var< const ULongInt & >(vm, idx).value.GetNum()); return ConvTo< SQInteger >::From(Var< const ULongInt & >(vm, idx).value.GetNum());
@ -336,9 +347,13 @@ SQInteger PopStackInteger(HSQUIRRELVM vm, SQInteger idx)
{ {
// Just ignore it... // Just ignore it...
} }
}
else
{
// Attempt to get the size of the instance as a fall back // Attempt to get the size of the instance as a fall back
return sq_getsize(vm, idx); return sq_getsize(vm, idx);
} }
}
default: break; default: break;
} }
// Default to 0 // Default to 0
@ -391,7 +406,15 @@ SQFloat PopStackFloat(HSQUIRRELVM vm, SQInteger idx)
} }
case OT_INSTANCE: case OT_INSTANCE:
{ {
// Attempt to treat the value as a signed long instance SQUserPointer tag;
// Attempt to retrieve the type tag
if (SQ_FAILED(sq_gettypetag(vm, -1, &tag)))
{
break;
}
// Is the instance SLongInt? (signed long)
else if (static_cast< AbstractStaticClassData * >(tag) == StaticClassTypeTag< SLongInt >::Get())
{
try try
{ {
return ConvTo< SQFloat >::From(Var< const SLongInt & >(vm, idx).value.GetNum()); return ConvTo< SQFloat >::From(Var< const SLongInt & >(vm, idx).value.GetNum());
@ -400,7 +423,10 @@ SQFloat PopStackFloat(HSQUIRRELVM vm, SQInteger idx)
{ {
// Just ignore it... // Just ignore it...
} }
// Attempt to treat the value as a unsigned long instance }
// Is the instance ULongInt? (unsigned long)
else if (static_cast< AbstractStaticClassData * >(tag) == StaticClassTypeTag< ULongInt >::Get())
{
try try
{ {
return ConvTo< SQFloat >::From(Var< const ULongInt & >(vm, idx).value.GetNum()); return ConvTo< SQFloat >::From(Var< const ULongInt & >(vm, idx).value.GetNum());
@ -409,9 +435,13 @@ SQFloat PopStackFloat(HSQUIRRELVM vm, SQInteger idx)
{ {
// Just ignore it... // Just ignore it...
} }
}
else
{
// Attempt to get the size of the instance as a fall back // Attempt to get the size of the instance as a fall back
return ConvTo< SQFloat >::From(sq_getsize(vm, idx)); return ConvTo< SQFloat >::From(sq_getsize(vm, idx));
} }
}
default: break; default: break;
} }
// Default to 0 // Default to 0