Author: Marek Kurdej Date: 2022-02-01T14:24:01+01:00 New Revision: e75a3428a92016b2689d5efb7ac95ae91761949d
URL: https://github.com/llvm/llvm-project/commit/e75a3428a92016b2689d5efb7ac95ae91761949d DIFF: https://github.com/llvm/llvm-project/commit/e75a3428a92016b2689d5efb7ac95ae91761949d.diff LOG: [clang-format] Use std::iota and reserve. NFC. This way we have at most 1 allocation even if the number of includes is greater than the on-stack size of the small vector. Added: Modified: clang/lib/Format/Format.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 70c7d4d3acee..9611e4ae33f8 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -44,6 +44,7 @@ #include <algorithm> #include <memory> #include <mutex> +#include <numeric> #include <string> #include <unordered_map> @@ -2521,8 +2522,8 @@ static void sortCppIncludes(const FormatStyle &Style, if (!affectsRange(Ranges, IncludesBeginOffset, IncludesEndOffset)) return; SmallVector<unsigned, 16> Indices; - for (unsigned i = 0, e = Includes.size(); i != e; ++i) - Indices.push_back(i); + Indices.resize(Includes.size()); + std::iota(Indices.begin(), Indices.end(), 0); if (Style.SortIncludes == FormatStyle::SI_CaseInsensitive) { llvm::stable_sort(Indices, [&](unsigned LHSI, unsigned RHSI) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits