summaryrefslogtreecommitdiff
path: root/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2014-04-15 08:28:06 +0000
committerDaniel Jasper <djasper@google.com>2014-04-15 08:28:06 +0000
commit3726781ffda25473708808dcb2f6fa9dce70079e (patch)
tree5efa979ccacaf66766568d578ca214d9f5949d5e /lib/Format/Format.cpp
parentdb5783685e00d5cc5cd9b0d9a44e968e5d04590b (diff)
downloadclang-3726781ffda25473708808dcb2f6fa9dce70079e.tar.gz
clang-3726781ffda25473708808dcb2f6fa9dce70079e.tar.bz2
clang-3726781ffda25473708808dcb2f6fa9dce70079e.tar.xz
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206260 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r--lib/Format/Format.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 2be21407f0..528e135610 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -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,