[llvm-commits] PATCH: Add raw_svector_ostream direct vector output

Chris Lattner clattner at apple.com
Tue Aug 18 23:37:18 PDT 2009


On Aug 18, 2009, at 10:27 PM, Daniel Dunbar wrote:

> Hi all,
>
> The attached patch changes raw_svector_ostream to use the vector
> buffer itself as the raw_ostream buffer. This is nice for a couple
> reasons:
> 1. It avoids the malloc/free of the raw_ostream buffer. This makes it
> very lightweight to use a raw_svector_ostream for simple string
> concatenation (e.g., the Twine::str method).
>
> 2. It avoids unnecessary copying of the data from the raw_ostream
> buffer to the vector buffer.
>
> I'm proposing as a patch because it has two downsides:
> 1. It exposes some bits of SmallVector; namely it adds a capacity()
> method, which gives the allocated size of the current buffer, and a
> set_size() method, which clients can use to forcibly set the vector
> size (without doing any construction or destruction). The use case is
> basically that clients will intentionally write past the end() of the
> vector (but not past the capacity() of the buffer), and then at some
> point call set_size() to update the vector size.
>
> 2. It forces clients of raw_svector_ostream to provide a SmallVector
> with at least 128 bytes free. This is probably a good thing, but it
> isn't enforced by the API (it is enforced by a runtime check, of
> course).

This approach seems reasonable to me.

-Chris




More information about the llvm-commits mailing list