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

Daniel Dunbar daniel at zuster.org
Tue Aug 18 22:27:27 PDT 2009


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).

Any objections?

 - Daniel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: raw_svector_ostream.patch
Type: application/octet-stream
Size: 4223 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20090818/20d95294/attachment.obj>


More information about the llvm-commits mailing list