[PATCH] D16044: getVariableName() for MemRegion

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 24 08:30:22 PST 2016

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.


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.


More information about the cfe-commits mailing list