1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

sq_newarrayex utility which reserves space only instead of creating elements.

This commit is contained in:
Sandu Liviu Catalin 2021-07-13 20:06:21 +03:00
parent 17733c9b5f
commit b3febf0017
2 changed files with 8 additions and 0 deletions

View File

@ -16,6 +16,7 @@ SQUIRREL_API SQRESULT sq_pushstringf(HSQUIRRELVM v,const SQChar *s,...);
SQUIRREL_API SQRESULT sq_vpushstringf(HSQUIRRELVM v,const SQChar *s,va_list l); SQUIRREL_API SQRESULT sq_vpushstringf(HSQUIRRELVM v,const SQChar *s,va_list l);
SQUIRREL_API SQRESULT sq_getnativeclosurepointer(HSQUIRRELVM v,SQInteger idx,SQFUNCTION *f); SQUIRREL_API SQRESULT sq_getnativeclosurepointer(HSQUIRRELVM v,SQInteger idx,SQFUNCTION *f);
SQUIRREL_API SQRESULT sq_arrayreserve(HSQUIRRELVM v,SQInteger idx,SQInteger newcap); SQUIRREL_API SQRESULT sq_arrayreserve(HSQUIRRELVM v,SQInteger idx,SQInteger newcap);
SQUIRREL_API void sq_newarrayex(HSQUIRRELVM v,SQInteger capacity);
SQUIRREL_API SQInteger sq_cmpr(HSQUIRRELVM v); SQUIRREL_API SQInteger sq_cmpr(HSQUIRRELVM v);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -120,6 +120,13 @@ SQRESULT sq_arrayreserve(HSQUIRRELVM v,SQInteger idx,SQInteger newcap)
return sq_throwerror(v,_SC("negative capacity")); return sq_throwerror(v,_SC("negative capacity"));
} }
void sq_newarrayex(HSQUIRRELVM v,SQInteger capacity)
{
SQArray* a = SQArray::Create(_ss(v), 0);
a->Reserve(capacity);
v->Push(a);
}
SQInteger sq_cmpr(HSQUIRRELVM v) SQInteger sq_cmpr(HSQUIRRELVM v)
{ {
SQInteger res; SQInteger res;