From: "Martin J. Dürst" Date: 2016-02-01T10:44:32+09:00 Subject: [ruby-core:73620] Re: [Ruby trunk - Feature #12024] Add String.buffer, for creating strings with large capacities On 2016/01/30 21:17, mame@ruby-lang.org wrote: > I have no strong objection, but still I have a question. I guess that creating a large string by concatenating many short strings is natural use case in Ruby. However, are there so much cases where we can predict the final length of a generated string before starting creating it? Usually, when doing something like result = "" loop do result << some_string end result this starts to get slow quite quickly. The standard advice (which I have myself used often) is to convert this to: result = [] loop do result << some_string end result.join This often speeds up things considerably. I haven't completely analyzed the code for Array#join, but on first impression, it seems to do exactly what you suggest: calculate the overall length first, then do the actual copying. Unsubscribe: