From 98583d522f5a371614c23cd6d07d2f40f7a8baa9 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 15 Apr 2014 08:28:06 +0000 Subject: [PATCH] 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. llvm-svn: 206260 --- clang/lib/Format/Format.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 2be21407f0c4..528e1356108e 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/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,