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 22:32

Because otherwise you end up allocating and copying excessively. The best thing you can possibly do is to use a StringBuffer/StringBuilder/whatever-the-fuck-it's-called object that tries to minimize extra copying and allocation.

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