local Buffer = {}
Buffer.__index = Buffer

function Buffer:write(...)
    local n = #self
    for i = 1, select("#", ...) do
        self[n+i] = select(i, ...)
    end
end

function Buffer:__tostring()
    return table.concat(self)
end

return function()
    return setmetatable({}, Buffer)
end

local Buffer = {}
Buffer.__index = Buffer

function Buffer:write(...)
    local length = self.length
    for i = 1, select("#", ...) do
        length = length + 1
        self[length] = select(i, ...)
    end
    self.length = length
end

function Buffer:__tostring()
    return table.concat(self)
end

return function()
    return setmetatable({length = 0}, Buffer)
end

Store buffer length in a field instead of using the length operator
Store buffer length in a field instead of using the length operator
