]> granicus.if.org Git - clang/commit
Better trade-off for excess characters vs. staying within the column limits.
authorManuel Klimek <klimek@google.com>
Fri, 1 Dec 2017 13:28:08 +0000 (13:28 +0000)
committerManuel Klimek <klimek@google.com>
Fri, 1 Dec 2017 13:28:08 +0000 (13:28 +0000)
commitb1bb1031169feaa6a2ba2fb939cbbb333e52245d
treebd0f8661101fc3a6d42d591aca229ba6aa2035ca
parent8b606298160e388d7f4f8846bd11d983f2b16e95
Better trade-off for excess characters vs. staying within the column limits.

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.

Differential Revision: https://reviews.llvm.org/D40605

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@319541 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Format/ContinuationIndenter.cpp
lib/Format/ContinuationIndenter.h
unittests/Format/FormatTest.cpp