summaryrefslogtreecommitdiffstats
path: root/lib/Format/FormatToken.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-11-23 10:22:59 +0000
committerDaniel Jasper <djasper@google.com>2013-11-23 10:22:59 +0000
commit6c9cefd8ba7711a78f45e8eb72d72a89101b4952 (patch)
tree9f2c202aec1f507f02a1662835bd950b9e1fba42 /lib/Format/FormatToken.cpp
parent641304eaf1b52425148ba2f646b74eada6ce4280 (diff)
clang-format: Prefer column layout if possible.
Add a severe penalty for not using column layout for braced lists. If there are solutions with column layout, these are generally preferable over bin-packed solutions. Before: std::vector<MyValues> aaaaaaaaaaaaaaaaaaa{ aaaaaaa, aaaaaaaaaa, aaaaa, aaaaaaaaaaaaaaa, aaa, aaaaaaaaaa, a, aaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaa, aaaaaaa, a }; After: std::vector<MyValues> aaaaaaaaaaaaaaaaaaa{ aaaaaaa, aaaaaaaaaa, aaaaa, aaaaaaaaaaaaaaa, aaa, aaaaaaaaaa, a, aaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaa, aaaaaaa, a }; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@195546 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/FormatToken.cpp')
-rw-r--r--lib/Format/FormatToken.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/Format/FormatToken.cpp b/lib/Format/FormatToken.cpp
index 8ac704a3bb..bab2425205 100644
--- a/lib/Format/FormatToken.cpp
+++ b/lib/Format/FormatToken.cpp
@@ -48,8 +48,11 @@ unsigned CommaSeparatedList::format(LineState &State,
// Find the best ColumnFormat, i.e. the best number of columns to use.
const ColumnFormat *Format = getColumnFormat(RemainingCodePoints);
+ // If no ColumnFormat can be used, the braced list would generally be
+ // bin-packed. Add a severe penalty to this so that column layouts are
+ // prefered if possible.
if (!Format)
- return 0;
+ return 10000;
// Format the entire list.
unsigned Penalty = 0;