1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +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,26 +318,41 @@ SQInteger PopStackInteger(HSQUIRRELVM vm, SQInteger idx)
} }
case OT_INSTANCE: case OT_INSTANCE:
{ {
// Attempt to treat the value as a signed long instance SQUserPointer tag;
try // Attempt to retrieve the type tag
if (SQ_FAILED(sq_gettypetag(vm, -1, &tag)))
{ {
return ConvTo< SQInteger >::From(Var< const SLongInt & >(vm, idx).value.GetNum()); break;
} }
catch (...) // Is the instance SLongInt? (signed long)
else if (static_cast< AbstractStaticClassData * >(tag) == StaticClassTypeTag< SLongInt >::Get())
{ {
// Just ignore it... try
{
return ConvTo< SQInteger >::From(Var< const SLongInt & >(vm, idx).value.GetNum());
}
catch (...)
{
// Just ignore it...
}
} }
// Attempt to treat the value as a unsigned long instance // Is the instance ULongInt? (unsigned long)
try else if (static_cast< AbstractStaticClassData * >(tag) == StaticClassTypeTag< ULongInt >::Get())
{ {
return ConvTo< SQInteger >::From(Var< const ULongInt & >(vm, idx).value.GetNum()); try
{
return ConvTo< SQInteger >::From(Var< const ULongInt & >(vm, idx).value.GetNum());
}
catch (...)
{
// Just ignore it...
}
} }
catch (...) else
{ {
// Just ignore it... // Attempt to get the size of the instance as a fall back
return sq_getsize(vm, idx);
} }
// Attempt to get the size of the instance as a fall back
return sq_getsize(vm, idx);
} }
default: break; default: break;
} }
@ -391,26 +406,41 @@ SQFloat PopStackFloat(HSQUIRRELVM vm, SQInteger idx)
} }
case OT_INSTANCE: case OT_INSTANCE:
{ {
// Attempt to treat the value as a signed long instance SQUserPointer tag;
try // Attempt to retrieve the type tag
if (SQ_FAILED(sq_gettypetag(vm, -1, &tag)))
{ {
return ConvTo< SQFloat >::From(Var< const SLongInt & >(vm, idx).value.GetNum()); break;
} }
catch (...) // Is the instance SLongInt? (signed long)
else if (static_cast< AbstractStaticClassData * >(tag) == StaticClassTypeTag< SLongInt >::Get())
{ {
// Just ignore it... try
{
return ConvTo< SQFloat >::From(Var< const SLongInt & >(vm, idx).value.GetNum());
}
catch (...)
{
// Just ignore it...
}
} }
// Attempt to treat the value as a unsigned long instance // Is the instance ULongInt? (unsigned long)
try else if (static_cast< AbstractStaticClassData * >(tag) == StaticClassTypeTag< ULongInt >::Get())
{ {
return ConvTo< SQFloat >::From(Var< const ULongInt & >(vm, idx).value.GetNum()); try
{
return ConvTo< SQFloat >::From(Var< const ULongInt & >(vm, idx).value.GetNum());
}
catch (...)
{
// Just ignore it...
}
} }
catch (...) else
{ {
// Just ignore it... // Attempt to get the size of the instance as a fall back
return ConvTo< SQFloat >::From(sq_getsize(vm, idx));
} }
// Attempt to get the size of the instance as a fall back
return ConvTo< SQFloat >::From(sq_getsize(vm, idx));
} }
default: break; default: break;
} }