Skip to content

Commit a4b1912

Browse files
committed
[lldb] Refactor helper by using iterators and in-place edits (NFC) (llvm#116876)
Based on post-commit review feedback by Felipe Piovezan! (cherry picked from commit 174899f)
1 parent 7e80550 commit a4b1912

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

lldb/source/Utility/DiagnosticsRendering.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,16 @@ void RenderDiagnosticDetails(Stream &stream,
132132
stream << '\n';
133133

134134
// Reverse the order within groups of diagnostics that are on the same column.
135-
auto group = [](const std::vector<DiagnosticDetail> &details) {
136-
uint16_t column = 0;
137-
std::vector<DiagnosticDetail> result, group;
138-
for (auto &d : details) {
139-
if (d.source_location->column == column) {
140-
group.push_back(d);
141-
continue;
142-
}
143-
result.insert(result.end(), group.rbegin(), group.rend());
144-
group.clear();
145-
column = d.source_location->column;
146-
group.push_back(d);
135+
auto group = [](std::vector<DiagnosticDetail> &details) {
136+
for (auto it = details.begin(), end = details.end(); it != end;) {
137+
auto eq_end = std::find_if(it, end, [&](const DiagnosticDetail &d) {
138+
return d.source_location->column != it->source_location->column;
139+
});
140+
std::reverse(it, eq_end);
141+
it = eq_end;
147142
}
148-
result.insert(result.end(), group.rbegin(), group.rend());
149-
return result;
150143
};
151-
remaining_details = group(remaining_details);
144+
group(remaining_details);
152145

153146
// Work through each detail in reverse order using the vector/stack.
154147
bool did_print = false;

0 commit comments

Comments
 (0)