Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Immutable String Buffers

Name: Anonymous 2011-09-17 22:28

Why is this telling me to concatenate small strings to the ends of large ones, but not in reverse, and then concatenate all remaining strings in the table?
http://www.lua.org/pil/11.6.html

Wouldn't it just be easier to put all the strings in a table then concatenate them all at once, as in the following?

function filetostring(file)
    local t == {}
    for line in io.lines(file)
        if line == "" then
            break
        end
        table.insert(t, line .. '\n')
   return table.concatenate(x)
end

I'm confused as fuck.

Name: Anonymous 2011-09-17 23:01

>>5
The best you can do in pure Lua without any external C code is to read every string into a table (without ever actually concatenating anything) and call table.concatenate at the very end. That will still take twice as much memory than it should, but at least the worst run-time is linear.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List