<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Apr 14, 2010, at 11:48 PM, Nick Lewycky wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div class="gmail_quote">On 14 April 2010 07:44, Douglas Gregor <span dir="ltr"><<a href="mailto:dgregor@apple.com">dgregor@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); margin-top: 0pt; margin-right: 0pt; margin-bottom: 0pt; margin-left: 0.8ex; padding-left: 1ex; position: static; z-index: auto; ">

<div style="word-wrap: break-word;"><div class="im"><br><div><div>On Apr 9, 2010, at 7:24 PM, Nick Lewycky wrote:</div></div></div><div><div>-bool FixItRewriter::WriteFixedFile(const std::string &InFileName,</div><div>-                                   const std::string &OutFileName) {</div>

<div>+bool FixItRewriter::WriteFixedFile(FileID ID, llvm::raw_ostream *OS) {</div><div>+  const RewriteBuffer *RewriteBuf = Rewrite.getRewriteBufferFor(ID);</div><div>+  if (!RewriteBuf) return true;</div><div>+  *OS << std::string(RewriteBuf->begin(), RewriteBuf->end());</div>

<div>+  OS->flush();</div><div>+  return false;</div><div>+}</div><div><br></div><div>Please use OS->write() instead of forming a temporary string. </div></div></div></blockquote><div><br>No can do. It's not backed by contiguous storage being a btree-string and there's no existing API to print these things without an std::string temporary. In a future patch I'll add a print(raw_ostream&) method to RewriteBuffer or one of its base classes, with the inefficient implementation and a FIXME to make it more awesome.<font class="Apple-style-span" color="#000000"><font class="Apple-style-span" color="#144FAE"><br></font></font></div></div></blockquote><div><br></div><div>Oh, right. Sorry for being dense.</div><div><br></div><blockquote type="cite"><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); margin-top: 0pt; margin-right: 0pt; margin-bottom: 0pt; margin-left: 0.8ex; padding-left: 1ex; position: static; z-index: auto; "><div style="word-wrap: break-word;"><div><div><div><font class="Apple-style-span" color="#000000"><br></font></div>
<div>
The "only fix the main file" approach was me being paranoid when fix-its first went it. I think the right answer now is for -fixit to always apply changes to all of the files (in place), and to allow a file name suffix, e.g.,</div>

<div><br></div><div><span style="white-space: pre;">    </span>1) -fixit changes files in-place</div><div><span style="white-space: pre;">       </span>2) -fixit=suffix puts the changes for any file "foo.c" into "foosuffix.c"; we'll mainly use this for testing, I think.</div>

<div><br></div><div>At this point, I trust fix-its enough that I'd like to add -fixit to my normal Clang build. I'm not worried about it because we should only write out the changed files if *all* errors have fix-its that were properly applied, so we only end up changing the source code when our changes produced a program that actually compiles.</div>

</div></div></div></blockquote><div><br>Yes, this sounds like the right way to go forward. I'll be happy to rip out the -fixit-at logic!<br></div></div></blockquote></div><div><br></div><div>I was going to type a long-winded defense of -fixit-at, but... yeah, it's really not worthwhile. Better to just -fixit inplace and get everything fixed (unless there were unfixable errors, naturally!).</div><div><div><br></div></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">       </span>- Doug</div></body></html>