<div dir="ltr">The patch itself looks good (I don't know why we didn't do that in the first place).<br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Nov 8, 2013 at 12:07 AM, Alp Toker <span dir="ltr"><<a href="mailto:alp@nuanti.com" target="_blank" class="cremed">alp@nuanti.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: alp<br>
Date: Fri Nov  8 02:07:19 2013<br>
New Revision: 194250<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=194250&view=rev" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project?rev=194250&view=rev</a><br>
Log:<br>
clang-format: Write files atomically<br>
<br>
Switch clang-format over to Rewriter::overwriteChangedFiles().<br>
<br>
The previous implementation was attempting to stream back directly to the<br>
original file and failing if it was already memory mapped by MemoryBuffer,<br>
an operation unsupported by Windows.<br>
<br>
MemoryBuffer generally mmaps files larger than the physical page size so<br>
this will have been difficult to reproduce consistently.<br>
<br>
This change also reduces flicker in code editors and IDEs on all platforms<br>
when reformatting in-place.<br></blockquote><div><br></div><div>I think it is generally a bad idea for IDEs to use in-place reformatting, but ok .. </div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Note that other incorrect uses of MemoryBuffer exist in LLVM/clang and<br>
will need a similar fix.<br>
<br>
A test should be added for Windows when libFormat performance issues are<br>
fixed (it takes longer than a day to format a 1MB file at present!)<br></blockquote><div><br></div><div>Is it the write that takes so long (i.e. fixed with this patch)?</div><div><br></div><div>If not, can the file be shared (or changed enough so that it can be shared)?</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Modified:<br>
    cfe/trunk/tools/clang-format/ClangFormat.cpp<br>
<br>
Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=194250&r1=194249&r2=194250&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=194250&r1=194249&r2=194250&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/tools/clang-format/ClangFormat.cpp (original)<br>
+++ cfe/trunk/tools/clang-format/ClangFormat.cpp Fri Nov  8 02:07:19 2013<br>
@@ -213,18 +213,8 @@ static bool format(std::string FileName)<br>
     Rewriter Rewrite(Sources, LangOptions());<br>
     tooling::applyAllReplacements(Replaces, Rewrite);<br>
     if (Inplace) {<br>
-      if (Replaces.size() == 0)<br>
-        return false; // Nothing changed, don't touch the file.<br>
-<br>
-      std::string ErrorInfo;<br>
-      llvm::raw_fd_ostream FileStream(FileName.c_str(), ErrorInfo,<br>
-                                      llvm::sys::fs::F_Binary);<br>
-      if (!ErrorInfo.empty()) {<br>
-        llvm::errs() << "Error while writing file: " << ErrorInfo << "\n";<br>
+      if (Rewrite.overwriteChangedFiles())<br>
         return true;<br>
-      }<br>
-      Rewrite.getEditBuffer(ID).write(FileStream);<br>
-      FileStream.flush();<br>
     } else {<br>
       if (Cursor.getNumOccurrences() != 0)<br>
         outs() << "{ \"Cursor\": " << tooling::shiftedCodePosition(<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" class="cremed">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank" class="cremed">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>