[PATCH] D33589: clang-format: consider not splitting tokens in optimization

Francois Ferrand via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 26 03:11:21 PDT 2017

Typz created this revision.
Herald added a subscriber: klimek.

This patch tries to improve the optimizer a bit, to avoid splitting
tokens (e.g. comments/strings) if only there are only few characters
beyond the ColumnLimit.

Previously, comments/strings would be split whenever they went beyond
the ColumnLimit, without consideration for the PenaltyBreakComment/
String and PenaltyExcessCharacter. With this patch, the
OptimizingLineFormatter will also consider not splitting each token,
so that these 'small' offenders get a chance:

  // With ColumnLimit=20
  int a; // the
         // comment
  // With ColumnLimit=20 and PenaltyExcessCharacter = 10
  int a; // the comment

This patch does not fully optimize the reflowing, as it will only try
reflowing the whole comment or not reflowing it at all (instead of
trying each split, to allow some lines of overflow ColumnLimit even
when reflowing).



-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33589.100378.patch
Type: text/x-patch
Size: 13737 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170526/9fdafd05/attachment.bin>

More information about the cfe-commits mailing list