aboutsummaryrefslogtreecommitdiff
path: root/src/script/common
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2020-04-14 20:44:18 +0200
committerGitHub <noreply@github.com>2020-04-14 20:44:18 +0200
commit2d5bd3bf794672285cfc796edebab2f672f2cab0 (patch)
treef4922fa8689156f33e9e37c32163cb719bd390e2 /src/script/common
parent7c43cf47c37b0204e34d12670d2e6975eb36b45a (diff)
downloadminetest-2d5bd3bf794672285cfc796edebab2f672f2cab0.tar.gz
minetest-2d5bd3bf794672285cfc796edebab2f672f2cab0.tar.bz2
minetest-2d5bd3bf794672285cfc796edebab2f672f2cab0.zip
scriptapi: Some small optimizations to value pushing (#9669)
Diffstat (limited to 'src/script/common')
-rw-r--r--src/script/common/c_content.cpp34
-rw-r--r--src/script/common/c_converter.cpp40
2 files changed, 37 insertions, 37 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index ff9ceec6d..d73ecedab 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -350,7 +350,7 @@ void push_object_properties(lua_State *L, ObjectProperties *prop)
push_v3f(L, prop->visual_size);
lua_setfield(L, -2, "visual_size");
- lua_newtable(L);
+ lua_createtable(L, prop->textures.size(), 0);
u16 i = 1;
for (const std::string &texture : prop->textures) {
lua_pushlstring(L, texture.c_str(), texture.size());
@@ -358,7 +358,7 @@ void push_object_properties(lua_State *L, ObjectProperties *prop)
}
lua_setfield(L, -2, "textures");
- lua_newtable(L);
+ lua_createtable(L, prop->colors.size(), 0);
i = 1;
for (const video::SColor &color : prop->colors) {
push_ARGB8(L, color);
@@ -840,7 +840,7 @@ void push_content_features(lua_State *L, const ContentFeatures &c)
lua_pushnumber(L, c.connect_sides);
lua_setfield(L, -2, "connect_sides");
- lua_newtable(L);
+ lua_createtable(L, c.connects_to.size(), 0);
u16 i = 1;
for (const std::string &it : c.connects_to) {
lua_pushlstring(L, it.c_str(), it.size());
@@ -963,7 +963,7 @@ void push_nodebox(lua_State *L, const NodeBox &box)
void push_box(lua_State *L, const std::vector<aabb3f> &box)
{
- lua_newtable(L);
+ lua_createtable(L, box.size(), 0);
u8 i = 1;
for (const aabb3f &it : box) {
push_aabb3f(L, it);
@@ -1040,7 +1040,7 @@ void read_soundspec(lua_State *L, int index, SimpleSoundSpec &spec)
void push_soundspec(lua_State *L, const SimpleSoundSpec &spec)
{
- lua_newtable(L);
+ lua_createtable(L, 0, 3);
lua_pushstring(L, spec.name.c_str());
lua_setfield(L, -2, "name");
lua_pushnumber(L, spec.gain);
@@ -1125,12 +1125,12 @@ MapNode readnode(lua_State *L, int index, const NodeDefManager *ndef)
/******************************************************************************/
void pushnode(lua_State *L, const MapNode &n, const NodeDefManager *ndef)
{
- lua_newtable(L);
+ lua_createtable(L, 0, 3);
lua_pushstring(L, ndef->get(n).name.c_str());
lua_setfield(L, -2, "name");
- lua_pushnumber(L, n.getParam1());
+ lua_pushinteger(L, n.getParam1());
lua_setfield(L, -2, "param1");
- lua_pushnumber(L, n.getParam2());
+ lua_pushinteger(L, n.getParam2());
lua_setfield(L, -2, "param2");
}
@@ -1163,7 +1163,7 @@ bool string_to_enum(const EnumString *spec, int &result,
{
const EnumString *esp = spec;
while(esp->str){
- if(str == std::string(esp->str)){
+ if (!strcmp(str.c_str(), esp->str)) {
result = esp->num;
return true;
}
@@ -1438,7 +1438,7 @@ ToolCapabilities read_tool_capabilities(
/******************************************************************************/
void push_dig_params(lua_State *L,const DigParams &params)
{
- lua_newtable(L);
+ lua_createtable(L, 0, 3);
setboolfield(L, -1, "diggable", params.diggable);
setfloatfield(L, -1, "time", params.time);
setintfield(L, -1, "wear", params.wear);
@@ -1447,7 +1447,7 @@ void push_dig_params(lua_State *L,const DigParams &params)
/******************************************************************************/
void push_hit_params(lua_State *L,const HitParams &params)
{
- lua_newtable(L);
+ lua_createtable(L, 0, 3);
setintfield(L, -1, "hp", params.hp);
setintfield(L, -1, "wear", params.wear);
}
@@ -1540,9 +1540,9 @@ void read_groups(lua_State *L, int index, ItemGroupList &result)
/******************************************************************************/
void push_groups(lua_State *L, const ItemGroupList &groups)
{
- lua_newtable(L);
+ lua_createtable(L, 0, groups.size());
for (const auto &group : groups) {
- lua_pushnumber(L, group.second);
+ lua_pushinteger(L, group.second);
lua_setfield(L, -2, group.first.c_str());
}
}
@@ -1587,7 +1587,7 @@ void luaentity_get(lua_State *L, u16 id)
lua_getglobal(L, "core");
lua_getfield(L, -1, "luaentities");
luaL_checktype(L, -1, LUA_TTABLE);
- lua_pushnumber(L, id);
+ lua_pushinteger(L, id);
lua_gettable(L, -2);
lua_remove(L, -2); // Remove luaentities
lua_remove(L, -2); // Remove core
@@ -1689,7 +1689,7 @@ static bool push_json_value_helper(lua_State *L, const Json::Value &value,
lua_pushboolean(L, value.asInt());
break;
case Json::arrayValue:
- lua_newtable(L);
+ lua_createtable(L, value.size(), 0);
for (Json::Value::const_iterator it = value.begin();
it != value.end(); ++it) {
push_json_value_helper(L, *it, nullindex);
@@ -1697,7 +1697,7 @@ static bool push_json_value_helper(lua_State *L, const Json::Value &value,
}
break;
case Json::objectValue:
- lua_newtable(L);
+ lua_createtable(L, 0, value.size());
for (Json::Value::const_iterator it = value.begin();
it != value.end(); ++it) {
#ifndef JSONCPP_STRING
@@ -1824,7 +1824,7 @@ void push_objectRef(lua_State *L, const u16 id)
lua_getglobal(L, "core");
lua_getfield(L, -1, "object_refs");
luaL_checktype(L, -1, LUA_TTABLE);
- lua_pushnumber(L, id);
+ lua_pushinteger(L, id);
lua_gettable(L, -2);
lua_remove(L, -2); // object_refs
lua_remove(L, -2); // core
diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp
index 3c2f75641..334af61c3 100644
--- a/src/script/common/c_converter.cpp
+++ b/src/script/common/c_converter.cpp
@@ -62,7 +62,7 @@ void push_float_string(lua_State *L, float value)
void push_v3f(lua_State *L, v3f p)
{
- lua_newtable(L);
+ lua_createtable(L, 0, 3);
lua_pushnumber(L, p.X);
lua_setfield(L, -2, "x");
lua_pushnumber(L, p.Y);
@@ -73,7 +73,7 @@ void push_v3f(lua_State *L, v3f p)
void push_v2f(lua_State *L, v2f p)
{
- lua_newtable(L);
+ lua_createtable(L, 0, 2);
lua_pushnumber(L, p.X);
lua_setfield(L, -2, "x");
lua_pushnumber(L, p.Y);
@@ -82,7 +82,7 @@ void push_v2f(lua_State *L, v2f p)
void push_v3_float_string(lua_State *L, v3f p)
{
- lua_newtable(L);
+ lua_createtable(L, 0, 3);
push_float_string(L, p.X);
lua_setfield(L, -2, "x");
push_float_string(L, p.Y);
@@ -93,7 +93,7 @@ void push_v3_float_string(lua_State *L, v3f p)
void push_v2_float_string(lua_State *L, v2f p)
{
- lua_newtable(L);
+ lua_createtable(L, 0, 2);
push_float_string(L, p.X);
lua_setfield(L, -2, "x");
push_float_string(L, p.Y);
@@ -115,19 +115,19 @@ v2s16 read_v2s16(lua_State *L, int index)
void push_v2s16(lua_State *L, v2s16 p)
{
- lua_newtable(L);
- lua_pushnumber(L, p.X);
+ lua_createtable(L, 0, 2);
+ lua_pushinteger(L, p.X);
lua_setfield(L, -2, "x");
- lua_pushnumber(L, p.Y);
+ lua_pushinteger(L, p.Y);
lua_setfield(L, -2, "y");
}
void push_v2s32(lua_State *L, v2s32 p)
{
- lua_newtable(L);
- lua_pushnumber(L, p.X);
+ lua_createtable(L, 0, 2);
+ lua_pushinteger(L, p.X);
lua_setfield(L, -2, "x");
- lua_pushnumber(L, p.Y);
+ lua_pushinteger(L, p.Y);
lua_setfield(L, -2, "y");
}
@@ -250,14 +250,14 @@ v3d check_v3d(lua_State *L, int index)
void push_ARGB8(lua_State *L, video::SColor color)
{
- lua_newtable(L);
- lua_pushnumber(L, color.getAlpha());
+ lua_createtable(L, 0, 4);
+ lua_pushinteger(L, color.getAlpha());
lua_setfield(L, -2, "a");
- lua_pushnumber(L, color.getRed());
+ lua_pushinteger(L, color.getRed());
lua_setfield(L, -2, "r");
- lua_pushnumber(L, color.getGreen());
+ lua_pushinteger(L, color.getGreen());
lua_setfield(L, -2, "g");
- lua_pushnumber(L, color.getBlue());
+ lua_pushinteger(L, color.getBlue());
lua_setfield(L, -2, "b");
}
@@ -274,12 +274,12 @@ v3f checkFloatPos(lua_State *L, int index)
void push_v3s16(lua_State *L, v3s16 p)
{
- lua_newtable(L);
- lua_pushnumber(L, p.X);
+ lua_createtable(L, 0, 3);
+ lua_pushinteger(L, p.X);
lua_setfield(L, -2, "x");
- lua_pushnumber(L, p.Y);
+ lua_pushinteger(L, p.Y);
lua_setfield(L, -2, "y");
- lua_pushnumber(L, p.Z);
+ lua_pushinteger(L, p.Z);
lua_setfield(L, -2, "z");
}
@@ -386,7 +386,7 @@ aabb3f read_aabb3f(lua_State *L, int index, f32 scale)
void push_aabb3f(lua_State *L, aabb3f box)
{
- lua_newtable(L);
+ lua_createtable(L, 6, 0);
lua_pushnumber(L, box.MinEdge.X);
lua_rawseti(L, -2, 1);
lua_pushnumber(L, box.MinEdge.Y);