https://github.com/adrian-prantl created https://github.com/llvm/llvm-project/pull/116876
Based on post-commit review feedback by Felipe Piovezan! >From 60d427280f59fdca843332cefa03d960d0fb6587 Mon Sep 17 00:00:00 2001 From: Adrian Prantl <apra...@apple.com> Date: Tue, 19 Nov 2024 12:51:50 -0800 Subject: [PATCH] [lldb] Refactor helper by using iterators and in-place edits (NFC) Based on post-commit review feedback by Felipe Piovezan! --- lldb/source/Utility/DiagnosticsRendering.cpp | 23 +++++++------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/lldb/source/Utility/DiagnosticsRendering.cpp b/lldb/source/Utility/DiagnosticsRendering.cpp index a20d82ad4eb678..f5aa27baadfef8 100644 --- a/lldb/source/Utility/DiagnosticsRendering.cpp +++ b/lldb/source/Utility/DiagnosticsRendering.cpp @@ -132,23 +132,16 @@ void RenderDiagnosticDetails(Stream &stream, stream << '\n'; // Reverse the order within groups of diagnostics that are on the same column. - auto group = [](const std::vector<DiagnosticDetail> &details) { - uint16_t column = 0; - std::vector<DiagnosticDetail> result, group; - for (auto &d : details) { - if (d.source_location->column == column) { - group.push_back(d); - continue; - } - result.insert(result.end(), group.rbegin(), group.rend()); - group.clear(); - column = d.source_location->column; - group.push_back(d); + auto group = [](std::vector<DiagnosticDetail> &details) { + for (auto it = details.begin(), end = details.end(); it != end;) { + auto eq_end = std::find_if(it, end, [&](const DiagnosticDetail &d) { + return d.source_location->column != it->source_location->column; + }); + std::reverse(it, eq_end); + it = eq_end; } - result.insert(result.end(), group.rbegin(), group.rend()); - return result; }; - remaining_details = group(remaining_details); + group(remaining_details); // Work through each detail in reverse order using the vector/stack. bool did_print = false; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits