[PATCH] D40605: Better trade-off for excess characters vs. staying within the column limits.

Manuel Klimek via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 29 07:53:44 PST 2017


klimek created this revision.

When we break a long line like:
Column limit: 21

                      |
  // foo foo foo foo foo foo foo foo foo foo foo foo

The local decision when to allow protruding vs. breaking can lead to this
outcome (2 excess characters, 2 breaks):

  // foo foo foo foo foo
  // foo foo foo foo foo
  // foo foo

While strictly staying within the column limit leads to this strictly better
outcome (fully below the column limit, 2 breaks):

  // foo foo foo foo
  // foo foo foo foo
  // foo foo foo foo

To get an optimal solution, we would need to consider all combinations of excess
characters vs. breaking for all lines, but that would lead to a significant
increase in the search space of the algorithm for little gain.

Instead, we blindly try both approches and·select the one that leads to the
overall lower penalty.


Repository:
  rC Clang

https://reviews.llvm.org/D40605

Files:
  lib/Format/ContinuationIndenter.cpp
  lib/Format/ContinuationIndenter.h
  unittests/Format/FormatTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40605.124752.patch
Type: text/x-patch
Size: 8516 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171129/c786d021/attachment-0001.bin>


More information about the cfe-commits mailing list