r206260 - clang-format: Early cut-off for inlining nested blocks.

Daniel Jasper djasper at google.com
Tue Apr 15 01:28:06 PDT 2014


Author: djasper
Date: Tue Apr 15 03:28:06 2014
New Revision: 206260

URL: http://llvm.org/viewvc/llvm-project?rev=206260&view=rev
Log:
clang-format: Early cut-off for inlining nested blocks.

Specifically, for a nested block or lambda, don't try to put the single
statement body inline, if it exceeds the column limit.

This should not change any observable behavior (as those would never
have led to the 'best' solution), but significantly speeds up formatting
time.

This fixes llvm.org/PR18761. Formatting time goes down from ~100s to a
few ms.

Modified:
    cfe/trunk/lib/Format/Format.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=206260&r1=206259&r2=206260&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Tue Apr 15 03:28:06 2014
@@ -1139,6 +1139,13 @@ private:
     if (Previous.Children[0]->Last->isTrailingComment())
       return false;
 
+    // If the child line exceeds the column limit, we wouldn't want to merge it.
+    // We add +2 for the trailing " }".
+    if (Style.ColumnLimit > 0 &&
+        Previous.Children[0]->Last->TotalLength + State.Column + 2 >
+            Style.ColumnLimit)
+      return false;
+
     if (!DryRun) {
       Whitespaces->replaceWhitespace(
           *Previous.Children[0]->First,





More information about the cfe-commits mailing list