summaryrefslogtreecommitdiffstats
path: root/lib/Format/FormatToken.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-05-08 13:51:14 +0000
committerDaniel Jasper <djasper@google.com>2015-05-08 13:51:14 +0000
commit04822968f375ac612ec771d291c034b158ba0e23 (patch)
tree4464d6ecb673e671b966813edabf24c2cc79bf4f /lib/Format/FormatToken.cpp
parent093c1675175c2c30a73e4779808d7c450d4b0161 (diff)
clang-format: Several improvements around formatting braced lists.
In particular: * If the difference between the longest and shortest element, we copped out of column format completely. Now, we instead allow to arrange these in a single column, essentially enforcing a one-per-line format. * Allow column layout even if there are braced lists. Especially, if there are many short lists, this can be beneficial. The bad case, where there is a long nested init list is usually caught as we now limit the length difference of the longest and shortest element. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236851 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/FormatToken.cpp')
-rw-r--r--lib/Format/FormatToken.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/Format/FormatToken.cpp b/lib/Format/FormatToken.cpp
index 0addbfed0c..cc1ef55fa4 100644
--- a/lib/Format/FormatToken.cpp
+++ b/lib/Format/FormatToken.cpp
@@ -199,13 +199,14 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
// create a column layout. If it has a nested list, column layout ensures one
// list element per line. If the difference between the shortest and longest
// element is too large, column layout would create too much whitespace.
- if (HasNestedBracedList || Commas.size() < 5 || Token->NestingLevel != 0 ||
- MaxItemLength - MinItemLength > 10)
+ if (Commas.size() < 5 || Token->NestingLevel != 0)
return;
// We can never place more than ColumnLimit / 3 items in a row (because of the
// spaces and the comma).
- for (unsigned Columns = 1; Columns <= Style.ColumnLimit / 3; ++Columns) {
+ unsigned MaxColumns =
+ MaxItemLength - MinItemLength > 10 ? 1 : Style.ColumnLimit / 3;
+ for (unsigned Columns = 1; Columns <= MaxColumns; ++Columns) {
ColumnFormat Format;
Format.Columns = Columns;
Format.ColumnSizes.resize(Columns);