Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

O(n) instead of O(n^2) string concactenation #54

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions Source.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ local table_unpack = table.unpack
local table_create = table.create
local table_insert = table.insert
local table_remove = table.remove
local table_concat = table.concat

local coroutine_create = coroutine.create
local coroutine_yield = coroutine.yield
Expand Down Expand Up @@ -1018,10 +1019,17 @@ local function luau_load(module, env, luau_settings)
local value = stack[inst.B]
stack[inst.A] = if value then value else inst.K or false
elseif op == 49 then --[[ CONCAT ]]
local s = ""
for i = inst.B, inst.C do
s ..= stack[i]
local B, C = inst.B, inst.C
local success, s = pcall(table_concat, stack, "", B, C)

if not success then
str = stack[B]

for i = B + 1, C do
str ..= stack[i]
end
end

stack[inst.A] = s
elseif op == 50 then --[[ NOT ]]
stack[inst.A] = not stack[inst.B]
Expand Down
Loading