r239604 - [clang-format] Hoist vector allocation out of loop. NFC.

Manuel Klimek klimek at google.com
Sun Jun 14 21:32:46 PDT 2015


Mentioning the benchmark you used in the description would have been
helpful to see what we get for the extra complexity.

On Fri, Jun 12, 2015, 3:15 PM Benjamin Kramer <benny.kra at googlemail.com>
wrote:

> Author: d0k
> Date: Fri Jun 12 08:06:57 2015
> New Revision: 239604
>
> URL: http://llvm.org/viewvc/llvm-project?rev=239604&view=rev
> Log:
> [clang-format] Hoist vector allocation out of loop. NFC.
>
> Modified:
>     cfe/trunk/lib/Format/FormatToken.cpp
>
> Modified: cfe/trunk/lib/Format/FormatToken.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.cpp?rev=239604&r1=239603&r2=239604&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Format/FormatToken.cpp (original)
> +++ cfe/trunk/lib/Format/FormatToken.cpp Fri Jun 12 08:06:57 2015
> @@ -203,11 +203,14 @@ void CommaSeparatedList::precomputeForma
>
>    // We can never place more than ColumnLimit / 3 items in a row (because
> of the
>    // spaces and the comma).
> -  for (unsigned Columns = 1; Columns <= Style.ColumnLimit / 3; ++Columns)
> {
> +  unsigned MaxItems = Style.ColumnLimit / 3;
> +  std::vector<unsigned> MinSizeInColumn;
> +  MinSizeInColumn.reserve(MaxItems);
> +  for (unsigned Columns = 1; Columns <= MaxItems; ++Columns) {
>      ColumnFormat Format;
>      Format.Columns = Columns;
>      Format.ColumnSizes.resize(Columns);
> -    std::vector<unsigned> MinSizeInColumn(Columns, UINT_MAX);
> +    MinSizeInColumn.assign(Columns, UINT_MAX);
>      Format.LineCount = 1;
>      bool HasRowWithSufficientColumns = false;
>      unsigned Column = 0;
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150615/1a51fb16/attachment.html>


More information about the cfe-commits mailing list