[PATCH] D91693: [Support] Add reserve() method to the raw_ostream.
James Henderson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 25 00:15:16 PST 2020
jhenderson added a comment.
I slightly lost track of what people are suggesting, so instead, I'm deliberately taking a step back from my knowledge of the existing code here, to outline an idealised theoretical design, so this might not work quite as planned. To me, it would make more sense for `executeObjcopyOnBinary` to take a filename and do the writing internally, rather than receiving some kind of input buffer that it writes to. This then means you should know the size up-front before writing to the buffer, if I'm not mistaken, allowing you to set the size of your buffer up front. That in turn removes the need for any resize/reserve method - you just specify the size needed at the construction of the buffer. You might therefore have two different stream classes being used, one for in-memory writes and the other for file writing. The two of them share a common base class, so only a small part of the code requires knowing what buffer kind to create. The in-memory version would just take a size (and possibly some backing storage), whilst the other takes a size and file name and creates a file, possibly via memory mapping, that ultimately is that size. It would be an assertion in these cases to write past the end of the file.
Ultimately, I think the only new code needed would be a new constructor overload for `raw_svector_ostream` taking a size that the output size will be and a new raw_ostream subclass which does the same with a file behind it.
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
More information about the llvm-commits