在学习第三方的Lua代码时,我发现在主脚本文件的顶部
local insert = table.insert
local match = string.match
local gsub = string.gsub我将这些块理解为快捷定义,但我也发现
local assert = assert
local ipairs = ipairs
local print = print最后这些指令的目的是什么?
发布于 2021-01-08 18:15:25
访问本地变量的速度更快。因此,在某些情况下,将频繁使用的内容放在本地以节省几个百分点的处理时间可能是有意义的。但在大多数情况下,你可以省去这些麻烦。特别是如果全局变量没有被使用数千次的话。
读一读这个:
Why are local variables accessed faster than global variables in lua?
http://lua-users.org/wiki/OptimisingUsingLocalVariables
发布于 2021-01-08 18:28:11
它在某些工作负载中提高了一点性能
https://stackoverflow.com/questions/65627054
复制相似问题