1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-01-19 12:07:13 +01:00

Minor optimizations in Sqrat when retrieving script strings.

This commit is contained in:
Sandu Liviu Catalin 2016-06-12 13:02:04 +03:00
parent d96a6dff0b
commit 67d6f54426

View File

@ -651,6 +651,7 @@ private:
public: public:
SQChar* value; ///< The actual value of get operations SQChar* value; ///< The actual value of get operations
SQInteger size; ///< The size of the obtained string
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Attempts to get the value off the stack at idx as a character array /// Attempts to get the value off the stack at idx as a character array
@ -662,7 +663,7 @@ public:
Var(HSQUIRRELVM vm, SQInteger idx) { Var(HSQUIRRELVM vm, SQInteger idx) {
sq_tostring(vm, idx); sq_tostring(vm, idx);
sq_getstackobj(vm, -1, &obj); sq_getstackobj(vm, -1, &obj);
sq_getstring(vm, -1, (const SQChar**)&value); sq_getstringandsize(vm, -1, (const SQChar**)&value, &size);
sq_addref(vm, &obj); sq_addref(vm, &obj);
sq_pop(vm,1); sq_pop(vm,1);
v = vm; v = vm;
@ -705,6 +706,7 @@ private:
public: public:
const SQChar* value; ///< The actual value of get operations const SQChar* value; ///< The actual value of get operations
SQInteger size; ///< The size of the obtained string
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Attempts to get the value off the stack at idx as a character array /// Attempts to get the value off the stack at idx as a character array
@ -716,7 +718,7 @@ public:
Var(HSQUIRRELVM vm, SQInteger idx) { Var(HSQUIRRELVM vm, SQInteger idx) {
sq_tostring(vm, idx); sq_tostring(vm, idx);
sq_getstackobj(vm, -1, &obj); sq_getstackobj(vm, -1, &obj);
sq_getstring(vm, -1, &value); sq_getstringandsize(vm, -1, &value, &size);
sq_addref(vm, &obj); sq_addref(vm, &obj);
sq_pop(vm,1); sq_pop(vm,1);
v = vm; v = vm;
@ -763,9 +765,10 @@ struct Var<string> {
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Var(HSQUIRRELVM vm, SQInteger idx) { Var(HSQUIRRELVM vm, SQInteger idx) {
const SQChar* ret; const SQChar* ret;
SQInteger len;
sq_tostring(vm, idx); sq_tostring(vm, idx);
sq_getstring(vm, -1, &ret); sq_getstringandsize(vm, -1, &ret, &len);
value = string(ret, sq_getsize(vm, -1)); value.assign(ret, len);
sq_pop(vm,1); sq_pop(vm,1);
} }
@ -798,9 +801,10 @@ struct Var<const string&> {
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Var(HSQUIRRELVM vm, SQInteger idx) { Var(HSQUIRRELVM vm, SQInteger idx) {
const SQChar* ret; const SQChar* ret;
SQInteger len;
sq_tostring(vm, idx); sq_tostring(vm, idx);
sq_getstring(vm, -1, &ret); sq_getstringandsize(vm, -1, &ret, &len);
value = string(ret, sq_getsize(vm, -1)); value.assign(ret, len);
sq_pop(vm,1); sq_pop(vm,1);
} }
@ -834,9 +838,10 @@ struct Var<std::string> {
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Var(HSQUIRRELVM vm, SQInteger idx) { Var(HSQUIRRELVM vm, SQInteger idx) {
const SQChar* ret; const SQChar* ret;
SQInteger len;
sq_tostring(vm, idx); sq_tostring(vm, idx);
sq_getstring(vm, -1, &ret); sq_getstringandsize(vm, -1, &ret, &len);
value = wstring_to_string(string(ret, sq_getsize(vm, -1))); value = wstring_to_string(string(ret, len));
sq_pop(vm,1); sq_pop(vm,1);
} }
@ -870,9 +875,10 @@ struct Var<const std::string&> {
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Var(HSQUIRRELVM vm, SQInteger idx) { Var(HSQUIRRELVM vm, SQInteger idx) {
const SQChar* ret; const SQChar* ret;
SQInteger len;
sq_tostring(vm, idx); sq_tostring(vm, idx);
sq_getstring(vm, -1, &ret); sq_getstringandsize(vm, -1, &ret, &len);
value = wstring_to_string(string(ret, sq_getsize(vm, -1))); value = wstring_to_string(string(ret, len));
sq_pop(vm,1); sq_pop(vm,1);
} }
@ -902,6 +908,7 @@ private:
public: public:
char* value; ///< The actual value of get operations char* value; ///< The actual value of get operations
String::size_type size; ///< The size of the obtained string
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Attempts to get the value off the stack at idx as a character array /// Attempts to get the value off the stack at idx as a character array
@ -913,14 +920,16 @@ public:
Var(HSQUIRRELVM vm, SQInteger idx) { Var(HSQUIRRELVM vm, SQInteger idx) {
std::string holder; std::string holder;
const SQChar *sv; const SQChar *sv;
SQInteger len;
sq_tostring(vm, idx); sq_tostring(vm, idx);
sq_getstackobj(vm, -1, &obj); sq_getstackobj(vm, -1, &obj);
sq_getstring(vm, -1, &sv); sq_getstringandsize(vm, -1, &sv, &len);
sq_addref(vm, &obj); sq_addref(vm, &obj);
sq_pop(vm,1); sq_pop(vm,1);
v = vm; v = vm;
holder = wstring_to_string(string(sv)); holder = wstring_to_string(string(sv, len));
value = strdup(holder.c_str()); value = strdup(holder.c_str());
size = holder.size();
} }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -961,6 +970,7 @@ private:
public: public:
char* value; ///< The actual value of get operations char* value; ///< The actual value of get operations
String::size_type size; ///< The size of the obtained string
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Attempts to get the value off the stack at idx as a character array /// Attempts to get the value off the stack at idx as a character array
@ -972,14 +982,16 @@ public:
Var(HSQUIRRELVM vm, SQInteger idx) { Var(HSQUIRRELVM vm, SQInteger idx) {
std::string holder; std::string holder;
const SQChar *sv; const SQChar *sv;
SQInteger len;
sq_tostring(vm, idx); sq_tostring(vm, idx);
sq_getstackobj(vm, -1, &obj); sq_getstackobj(vm, -1, &obj);
sq_getstring(vm, -1, &sv); sq_getstringandsize(vm, -1, &sv, &len);
sq_addref(vm, &obj); sq_addref(vm, &obj);
sq_pop(vm,1); sq_pop(vm,1);
v = vm; v = vm;
holder = wstring_to_string(string(sv)); holder = wstring_to_string(string(sv, len));
value = strdup(holder.c_str()); value = strdup(holder.c_str());
size = holder.size();
} }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////