Re: PATCH: Speed up direct string concatenation by 20+%!

Larry Hastings wrote:

The core concept: adding two strings together no longer returns a pure
"string" object. Instead, it returns a "string concatenation" object
which holds references to the two strings but does not actually
them... yet. The strings are concatenated only when someone requests
string's value, at which point it allocates all the space it needs and
renders the concatenated string all at once.

More to the point, if you add multiple strings together (a + b + c),
it *doesn't* compute the intermediate strings (a + b).

Upsides to this approach:

wouldn't this approach apply to other additions eg list+list seq+seq etc etc.

I suppose the utility of such an approach depends on the frequency with which multiple strings/lists/sequences etc are added together in real code.
Robin Becker

Relevant Pages

  • Re: passing pointers [C]
    ... >I could malloc some space, concatenate the first two, malloc some more, ... >strings, do that malloc, and return a new string. ... Since you only call realloc, there is no way for old allocations not ...
  • Re: was: Current Uses for Fortran ??
    ... > Strange because no other programming languages do it. ... > numbers and strings. ... I don't like + for concatenate since I believe that concatenate ... no deficiencies and the other way is to make it so complicated ...
  • passing pointers [C]
    ... My app has to concatenate strings to build up a bunch of SQL queries ... I could malloc some space, concatenate the first two, malloc some more, ... gradually built up) and realloc-ing it's memory block. ...
  • Re: Best practices for efficient FP string building in CL?
    ... CONCATENATE fast: ... (defun smarter-concatenate-strings (strings) ... (defun not-so-clever-concatenate (strings) ...
  • Re: Console.WriteLine(s) Is Missing Line Terminator?
    ... If I don't know if those are strings or numerics, ... It's the ease with which it encourages lazy programming that puts me off ... Matius is arguing strongly that '+' should not be used to concatenate ... reasons", to me it's like saying "Say Hasta La Vista to ...