История изменений
Исправление dissident, (текущая версия) :
Потому что строки в Lua immutable.
Поэтому первое сначала создает новую строку размером достаточным для ndata + row и пихает туда row и ndata, а следом создает еще одну строку размером ndata + row + «\n» и пихает туда предыдущую и «\n».
Трюк с table.insert - это как StringBuilder в Java. В таблицу пихаешь строки, не создавая временных переменных.
Правда в конце надо собрать все что в таблице в одну строку
s = table.concat(t)
Но эта операция O(N), т.е. сразу создает одну большую строку и пихает все в нее.
Больше информации, например, тут https://www.lua.org/pil/11.6.html.
А Lua как раз быстрая, потому что это Virtual Machine, да еще и «register-based». Ее часто встраивают в игры именно поэтому. Тут можно почитать об этом больше:
Bytecode VMs come in two main flavors: stack-based and register-based. In a stack-based VM, instructions always work from the top of the stack, like in our sample code. For example, INST_ADD pops two values, adds them, and pushes the result.
Register-based VMs still have a stack. The only difference is that instructions can read their inputs from deeper in the stack. Instead of INST_ADD always popping its operands, it has two indexes stored in the bytecode that identify where in the stack to read the operands from.
Register-based VMs got a reputation for being a bit faster after Lua converted to that style
Исправление dissident, :
Потому что строки в Lua immutable.
Поэтому первое сначала создает новую строку размером достаточным для ndata + row и пихает туда row и ndata, а следом создает еще одну строку размером ndata + row + «\n» и пихает туда предыдущую и «\n».
Трюк с table.insert - это как StringBuilder в Java. В таблицу пихаешь строки, не создавая временных переменных.
Правда в конце надо собрать все что в таблице в одну строку
s = table.concat(t)
Но эта операция O(N), т.е. сразу создает одну большую строку и пихает все в нее.
Больше информации, например, тут https://www.lua.org/pil/11.6.html.
А Lua как раз быстрая, потому что это Virtual Machine, да еще и register-based". Ее часто встраивают в игры именно поэтому. Тут можно почитать об этом больше:
Bytecode VMs come in two main flavors: stack-based and register-based. In a stack-based VM, instructions always work from the top of the stack, like in our sample code. For example, INST_ADD pops two values, adds them, and pushes the result.
Register-based VMs still have a stack. The only difference is that instructions can read their inputs from deeper in the stack. Instead of INST_ADD always popping its operands, it has two indexes stored in the bytecode that identify where in the stack to read the operands from.
Register-based VMs got a reputation for being a bit faster after Lua converted to that style
Исправление dissident, :
Потому что строки в Lua immutable.
Поэтому первое сначала создает новую строку размером достаточным для ndata + row и пихает туда row и ndata, а следом создает еще одну строку размером ndata + row + «\n» и пихает туда предыдущую и «\n».
Трюк с table.insert - это как StringBuilder в Java. В таблицу пихаешь строки, не создавая временных переменных.
Правда в конце надо собрать все что в таблице в одну строку
s = table.concat(t)
Но эта операция O(N), т.е. сразу создает одну большую строку и пихает все в нее.
Больше информации, например, тут https://www.lua.org/pil/11.6.html.
А Lua как раз быстрая, потому что это Virtual Machine, да еще и register-based". Ее часто встраивают в игры именно поэтому. Тут можно почитать об этом больше
Bytecode VMs come in two main flavors: stack-based and register-based. In a stack-based VM, instructions always work from the top of the stack, like in our sample code. For example, INST_ADD pops two values, adds them, and pushes the result.
Register-based VMs still have a stack. The only difference is that instructions can read their inputs from deeper in the stack. Instead of INST_ADD always popping its operands, it has two indexes stored in the bytecode that identify where in the stack to read the operands from.
Register-based VMs got a reputation for being a bit faster after Lua converted to that style
Исправление dissident, :
Потому что строки в Lua immutable.
Поэтому первое сначала создает новую строку размером достаточным для ndata + row и пихает туда row и ndata, а следом создает еще одну строку раземером ndata + row + «\n» и пихает туда предыдущую и «\n».
Трюк с table.insert - это как StringBuilder в Java. В таблицу пихаешь строки, не создавая временных переменных.
Правда в конце надо собрать все что в таблице в одну строку
s = table.concat(t)
Но эта операция O(N), т.е. сразу создает одну большую строку и пихает все в нее.
Больше информации, например, тут https://www.lua.org/pil/11.6.html.
А Lua как раз быстрая, потому что это Virtual Machine, да еще и register-based". Ее часто встраивают в игры именно поэтому. Тут можно почитать об этом больше
Bytecode VMs come in two main flavors: stack-based and register-based. In a stack-based VM, instructions always work from the top of the stack, like in our sample code. For example, INST_ADD pops two values, adds them, and pushes the result.
Register-based VMs still have a stack. The only difference is that instructions can read their inputs from deeper in the stack. Instead of INST_ADD always popping its operands, it has two indexes stored in the bytecode that identify where in the stack to read the operands from.
Register-based VMs got a reputation for being a bit faster after Lua converted to that style
Исправление dissident, :
Потому что строки в Lua immutable.
Поэтому первое сначала создает новую строку размером достаточным для ndata + row и пихает туда row и ndata, а следом создает еще одну строку раземером ndata + row + «\n» и пихает туда предыдущую и «\n».
Трюк с table.insert - это как StringBuilder в Java. В таблицу пихаешь строки, не создавая временных переменных.
Правда в конце надо собрать все что в таблице в одну строку
s = table.concat(t)
Но эта операция O(N), т.е. сразу создает одну большую строку и пихает все сюда.
Больше информации, например, тут https://www.lua.org/pil/11.6.html.
А Lua как раз быстрая, потому что это Virtual Machine, да еще и register-based". Ее часто встраивают в игры именно поэтому. Тут можно почитать об этом больше
Bytecode VMs come in two main flavors: stack-based and register-based. In a stack-based VM, instructions always work from the top of the stack, like in our sample code. For example, INST_ADD pops two values, adds them, and pushes the result.
Register-based VMs still have a stack. The only difference is that instructions can read their inputs from deeper in the stack. Instead of INST_ADD always popping its operands, it has two indexes stored in the bytecode that identify where in the stack to read the operands from.
Register-based VMs got a reputation for being a bit faster after Lua converted to that style
Исправление dissident, :
Потому что строки в Lua immutable.
Поэтому первое сначала создает новую строку размером достаточным для ndata + row и пихает туда row и ndata, а следом создает еще одну строку раземером ndata + row + «\n» и пихает туда предыдущую и «\n».
Трюк с table.insert - это как StringBuilder в Java.
Правда в конце надо собрать все что в таблице в одну строку
s = table.concat(t)
Больше информации, например, тут https://www.lua.org/pil/11.6.html.
А Lua как раз быстрая, потому что это Virtual Machine, да еще и register-based". Ее часто встраивают в игры именно поэтому. Тут можно почитать об этом больше
Bytecode VMs come in two main flavors: stack-based and register-based. In a stack-based VM, instructions always work from the top of the stack, like in our sample code. For example, INST_ADD pops two values, adds them, and pushes the result.
Register-based VMs still have a stack. The only difference is that instructions can read their inputs from deeper in the stack. Instead of INST_ADD always popping its operands, it has two indexes stored in the bytecode that identify where in the stack to read the operands from.
Register-based VMs got a reputation for being a bit faster after Lua converted to that style
Исходная версия dissident, :
Потому что строки в Lua immutable.
Поэтому первое сначала создает новую строку размером достаточным для ndata + row и пихает туда row и ndata, а следом создает еще одну строку раземером ndata + row + «\n» и пихает туда предыдущую и «\n».
Трюк с table.insert - это как StringBuilder в Java.
Правда в конце надо собрать все что в таблице в одну строку
[code=]s = table.concat(t)
Больше информации, например, тут https://www.lua.org/pil/11.6.html.
А Lua как раз быстрая, потому что это Virtual Machine, да еще и register-based". Ее часто встраивают в игры именно поэтому. Тут можно почитать об этом больше
Bytecode VMs come in two main flavors: stack-based and register-based. In a stack-based VM, instructions always work from the top of the stack, like in our sample code. For example, INST_ADD pops two values, adds them, and pushes the result.
Register-based VMs still have a stack. The only difference is that instructions can read their inputs from deeper in the stack. Instead of INST_ADD always popping its operands, it has two indexes stored in the bytecode that identify where in the stack to read the operands from.
Register-based VMs got a reputation for being a bit faster after Lua converted to that style