clang-format: Handle trailing commas in column layout of braced list.

Before, this was causing errors.

Also exit early in breakProtrudingToken() (before the expensive call to
SourceManager::getSpellingColumnNumber()). This makes formatting huge
(100k+-item) braced lists possible.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189094 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Format/FormatToken.cpp b/lib/Format/FormatToken.cpp
index 4e232af..1b6d360 100644
--- a/lib/Format/FormatToken.cpp
+++ b/lib/Format/FormatToken.cpp
@@ -92,6 +92,11 @@
   SmallVector<unsigned, 8> EndOfLineItemLength;
 
   for (unsigned i = 0, e = Commas.size() + 1; i != e; ++i) {
+    // If there is a trailing comma in the list, the next item will start at the
+    // closing brace. Don't create an extra item for this.
+    if (ItemBegin == Token->MatchingParen)
+      break;
+
     // Skip comments on their own line.
     while (ItemBegin->HasUnescapedNewline && ItemBegin->isTrailingComment())
       ItemBegin = ItemBegin->Next;