• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

lujian101/LuaTableOptimizer: simple readonly lua table optimizer

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

lujian101/LuaTableOptimizer

开源软件地址(OpenSource Url):

https://github.com/lujian101/LuaTableOptimizer

开源编程语言(OpenSource Language):

Lua 100.0%

开源软件介绍(OpenSource Introduction):

LuaTableOptimizer


Simple readonly lua table optimizer

Lua Table 通常被用来存储游戏的配置数据,如果配置中有很多冗余重复的数据那么将占用较多的内存,严重影响加载速度

Lua table commonly use to store configuration data for games. it takes a lot of memory if it contains many fields with same value. this optimization could improve memory usage and loading speed.

功能

  • 获取字段中使用最多次数的值作为默认值,并且删除默认值字段
  • 使用了非ASCII字符集字符的字段被视为需要做多语言化处理并提取替换成特殊标识符
  • 唯一化所有的子table,并且指向同一个引用,以节约内存

Features

  • remove default value fields ( store them into metatable )
  • auto localization
  • reuse all table values to save memory

Require

  • The key of root table must be all string or number type

Before

{
	{
		1,
		2,
		3,
		a = "123",
		b = "123"
	},
	{
		1,
		2,
		3,
		a = "123",
		b = "123"
	},
	{
		1,
		2,
		5,
		a = "123",
		b = "123"
	},
	[9] = {
		1,
		2,
		5,
		a = "123",
		b = "123"
	},
	[11] = {
		1,
		2,
		3,
		a = "123",
		b = "123",
		c = {
			{
				1
			},
			{
				1
			},
			{
				2
			},
			{
				2
			}
		},
		d = {
			{
				1,
				a = 1
			},
			{
				2,
				a = 2
			}
		},
		e = {
			{
				1,
				a = 1
			},
			{
				2,
				a = 2
			}
		}
	},
	[100] = {
		1,
		2,
		3,
		a = "tttt",
		b = "123"
	}
}

Optimized

local __rt_1 = {
}
local __rt_2 = {
	1,
	2,
	3
}
local __rt_3 = {
	1,
	2,
	5
}
local __rt_4 = {
	{
		1,
		a = 1
	},
	{
		2,
		a = 2
	}
}
local __rt_5 = {
	1
}
local __rt_6 = {
	2
}
local test = 
{
	__rt_2,
	__rt_2,
	__rt_3,
	[9] = __rt_3,
	[11] = {
		1,
		2,
		3,
		c = {
			__rt_5,
			__rt_5,
			__rt_6,
			__rt_6
		},
		d = __rt_4,
		e = __rt_4
	},
	[100] = {
		1,
		2,
		3,
		a = "tttt"
	}
}
local __default_values = {
	a = "123",
	b = "123",
	c = __rt_1,
	d = __rt_1,
	e = __rt_1
}
do
	local base = { __index = __default_values, __newindex = function() error( "Attempt to modify read-only table" ) end }
	for k, v in pairs( test ) do
		setmetatable( v, base )
	end
	base.__metatable = false
end

return test



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
brunoos/luasec: LuaSec发布时间:2022-08-16
下一篇:
cloudwu/lua-snapshot: Make a snapshot for lua state to detect memory leaks.发布时间:2022-08-16
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap