Skip to content

Commit

Permalink
[clang-format] disable bin packing for array initializers
Browse files Browse the repository at this point in the history
  • Loading branch information
Connor Smith committed Nov 15, 2017
1 parent 284bea2 commit 0c21f70
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
14 changes: 5 additions & 9 deletions lib/Format/FormatToken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,13 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
!Token->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare))
return;

// In C++11 braced list style, we should not format in columns unless they
// have many items (20 or more) or we allow bin-packing of function call
// arguments.
if (Style.Cpp11BracedListStyle && !Style.BinPackArguments &&
Commas.size() < 19)
// In C++11 braced list style, we should not format in columns unless we
// allow bin-packing of function call arguments.
if (Style.Cpp11BracedListStyle && !Style.BinPackArguments)
return;

// Limit column layout for JavaScript array initializers to 20 or more items
// for now to introduce it carefully. We can become more aggressive if this
// necessary.
if (Token->is(TT_ArrayInitializerLSquare) && Commas.size() < 19)
// The same applies to JavaScript array literals.
if (Token->is(TT_ArrayInitializerLSquare) && !Style.BinPackArguments)
return;

// Column format doesn't really make sense if we don't align after brackets.
Expand Down
4 changes: 3 additions & 1 deletion unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6571,6 +6571,8 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
// In combination with BinPackArguments = false.
FormatStyle NoBinPacking = getLLVMStyle();
NoBinPacking.BinPackArguments = false;
FormatStyle YesBinPacking = getLLVMStyle();
YesBinPacking.BinPackArguments = true;
verifyFormat("const Aaaaaa aaaaa = {aaaaa,\n"
" bbbbb,\n"
" ccccc,\n"
Expand Down Expand Up @@ -6603,7 +6605,7 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
" iiiiii, jjjjjj, kkkkkk, aaaaa, bbbbb, ccccc, ddddd, eeeee,\n"
" ffffff, ggggg, hhhhhh, iiiiii, jjjjjj, kkkkkk,\n"
"};",
NoBinPacking);
YesBinPacking);

// FIXME: The alignment of these trailing comments might be bad. Then again,
// this might be utterly useless in real code.
Expand Down

0 comments on commit 0c21f70

Please sign in to comment.