[clang] 35493b4 - [clang-format][NFC] Replace deque with vector
Björn Schäpers via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 5 03:32:12 PST 2022
Author: Björn Schäpers
Date: 2022-01-05T12:31:34+01:00
New Revision: 35493b45603fc897280cfba60866075888d9a790
URL: https://github.com/llvm/llvm-project/commit/35493b45603fc897280cfba60866075888d9a790
DIFF: https://github.com/llvm/llvm-project/commit/35493b45603fc897280cfba60866075888d9a790.diff
LOG: [clang-format][NFC] Replace deque with vector
I think the deque was chosen because of a better push_front, but in
combination with llvm::reverse the push_back'ed vector should be the
better choice.
Differential Revision: https://reviews.llvm.org/D115064
Added:
Modified:
clang/lib/Format/UnwrappedLineFormatter.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 5ba5958fbd53d..18a9685ce431a 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1108,22 +1108,22 @@ class OptimizingLineFormatter : public LineFormatter {
/// Applies the best formatting by reconstructing the path in the
/// solution space that leads to \c Best.
void reconstructPath(LineState &State, StateNode *Best) {
- std::deque<StateNode *> Path;
+ llvm::SmallVector<StateNode *> Path;
// We do not need a break before the initial token.
while (Best->Previous) {
- Path.push_front(Best);
+ Path.push_back(Best);
Best = Best->Previous;
}
- for (auto I = Path.begin(), E = Path.end(); I != E; ++I) {
+ for (const auto &Node : llvm::reverse(Path)) {
unsigned Penalty = 0;
- formatChildren(State, (*I)->NewLine, /*DryRun=*/false, Penalty);
- Penalty += Indenter->addTokenToState(State, (*I)->NewLine, false);
+ formatChildren(State, Node->NewLine, /*DryRun=*/false, Penalty);
+ Penalty += Indenter->addTokenToState(State, Node->NewLine, false);
LLVM_DEBUG({
- printLineState((*I)->Previous->State);
- if ((*I)->NewLine) {
+ printLineState(Node->Previous->State);
+ if (Node->NewLine) {
llvm::dbgs() << "Penalty for placing "
- << (*I)->Previous->State.NextToken->Tok.getName()
+ << Node->Previous->State.NextToken->Tok.getName()
<< " on a new line: " << Penalty << "\n";
}
});
More information about the cfe-commits
mailing list