util-src: Specify size of various tables to be allocated
authorKim Alvefur <zash@zash.se>
Thu, 09 Mar 2017 01:20:59 +0100
changeset 7972 1c6a07606309
parent 7971 f0e35f4db9e0
child 7973 924354a35a02
child 7974 cd6f88012f67
util-src: Specify size of various tables to be allocated
util-src/crand.c
util-src/net.c
util-src/pposix.c
util-src/ringbuffer.c
util-src/table.c
--- a/util-src/crand.c	Thu Mar 09 00:59:32 2017 +0100
+++ b/util-src/crand.c	Thu Mar 09 01:20:59 2017 +0100
@@ -100,7 +100,7 @@
 	luaL_checkversion(L);
 #endif
 
-	lua_newtable(L);
+	lua_createtable(L, 0, 2);
 	lua_pushcfunction(L, Lrandom);
 	lua_setfield(L, -2, "bytes");
 
--- a/util-src/net.c	Thu Mar 09 00:59:32 2017 +0100
+++ b/util-src/net.c	Thu Mar 09 01:20:59 2017 +0100
@@ -134,7 +134,7 @@
 		{ NULL, NULL }
 	};
 
-	lua_newtable(L);
+	lua_createtable(L, 0, 1);
 	luaL_setfuncs(L, exports, 0);
 	return 1;
 }
--- a/util-src/pposix.c	Thu Mar 09 00:59:32 2017 +0100
+++ b/util-src/pposix.c	Thu Mar 09 01:20:59 2017 +0100
@@ -660,7 +660,7 @@
 		return 2;
 	}
 
-	lua_newtable(L);
+	lua_createtable(L, 0, 6);
 	lua_pushstring(L, uname_info.sysname);
 	lua_setfield(L, -2, "sysname");
 	lua_pushstring(L, uname_info.nodename);
@@ -709,7 +709,7 @@
 #ifdef WITH_MALLINFO
 int lc_meminfo(lua_State *L) {
 	struct mallinfo info = mallinfo();
-	lua_newtable(L);
+	lua_createtable(L, 0, 5);
 	/* This is the total size of memory allocated with sbrk by malloc, in bytes. */
 	lua_pushinteger(L, info.arena);
 	lua_setfield(L, -2, "allocated");
--- a/util-src/ringbuffer.c	Thu Mar 09 00:59:32 2017 +0100
+++ b/util-src/ringbuffer.c	Thu Mar 09 01:20:59 2017 +0100
@@ -187,7 +187,7 @@
 		lua_pushcfunction(L, rb_length);
 		lua_setfield(L, -2, "__len");
 
-		lua_newtable(L); /* __index */
+		lua_createtable(L, 0, 7); /* __index */
 		{
 			lua_pushcfunction(L, rb_find);
 			lua_setfield(L, -2, "find");
@@ -207,7 +207,7 @@
 		lua_setfield(L, -2, "__index");
 	}
 
-	lua_newtable(L);
+	lua_createtable(L, 0, 1);
 	lua_pushcfunction(L, rb_new);
 	lua_setfield(L, -2, "new");
 	return 1;
--- a/util-src/table.c	Thu Mar 09 00:59:32 2017 +0100
+++ b/util-src/table.c	Thu Mar 09 01:20:59 2017 +0100
@@ -24,7 +24,7 @@
 #if (LUA_VERSION_NUM > 501)
 	luaL_checkversion(L);
 #endif
-	lua_newtable(L);
+	lua_createtable(L, 0, 2);
 	lua_pushcfunction(L, Lcreate_table);
 	lua_setfield(L, -2, "create");
 	lua_pushcfunction(L, Lpack);