xazax.hun added a comment.

In http://reviews.llvm.org/D16044#360737, @Alexander_Droste wrote:

> Hi Gábor,
>  Is it really possible to reduce string copying in this case, with the help 
> of `llvm::Twine`?
>  The problem with `llvm::Twine` seems to me that it cannot be modified after 
> initialisation. 
>  So there's no way to do sth. like: `Twine t("a" + "b"); t += "c"`. A new 
> Twine object needs to
>  be created for each subsequent concatenation. Do you have an idea how twine 
> could be
>  applied here? Else I would claim that this function gets only used for 
> diagnostics why 
>  this level of efficiency might not be required.


Hi!

It works the following way:

If you write something like A = B + C + D; it will create two temporary 
strings, all of them might allocate memory.
If you write something like A = (Twine(B) + C + D).str(); it will only do one 
temporary string and one allocation. 
So basically twine creates a data structure of pointers that points to the 
strings that you would like to concatenate, and once you do the conversion to 
string, it will do all the concatenations with one allocation.


http://reviews.llvm.org/D16044



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to