Introduce StringBuilder utility around raw_string_ostream

Benjamin Kramer benny.kra at gmail.com
Tue Jul 1 00:44:30 PDT 2014


On Tue, Jul 1, 2014 at 1:17 AM, Alp Toker <alp at nuanti.com> wrote:
>
> On 01/07/2014 01:12, Chandler Carruth wrote:
>>
>> Just as a very small correction to some of the facts here:
>>
>> On Mon, Jun 30, 2014 at 2:24 PM, Alp Toker <alp at nuanti.com
>> <mailto:alp at nuanti.com>> wrote:
>>
>>     1) Uses a non-heap container (SmallString) by default.
>>
>>
>> std::string has a small-string optimization in both libc++ and, whenever
>> GCC takes the ABI break and conforms with C++11, libstdc++
>
>
> That's an optimization for strings less than 10-22 characters, and is
> libc++-specific. Worst of all it's non-customizable and pessimal, say, if we
> *know* the string is likely to be, say, 40 bytes at a certain point-of-use.
>
> Examining the hundreds of SmallStrings in the LLVM code base, only a handful
> out of those would benefit in any way from libc++'s small string feature
> with the remainder thrashing the heap. The proposed patch does a great job
> with all of them.
>

The reason why most of them are instantiated for 128 bytes is that
raw_svector_ostream allocates a buffer of at least 128 bytes which
makes smaller SmallStrings useless. The actual string stored will be
much smaller most of the time.

- Ben

>>
>> So you don't have to use SmallString to avoid heap allocations. The
>> primary advantage of SmallString is the ability to customize how many bytes
>> are available in the internal buffer.
>
>
> Yes, the proposed patch frequently overrides the suggested 128 byte stack
> buffer size in cases where we have a better idea how large our string will
> be.
>
> I'm familiar with libc++ and other standard C++ libraries, and basically
> don't see any overlap with the string facilities provided there. As Yaron
> pointed out, this is much more a natural continuation of ADT's data types.
>
> Alp.
>
>
>
> --
> http://www.nuanti.com
> the browser experts
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list