Make more use of llvm STLExtras (#4668)

This is essentially the result of looking at `.begin()` uses. We also
frequently do `std::shuffle`, but unfortunately STLExtras doesn't
provide a wrapper for that.
This commit is contained in:
Jon Ross-Perkins
2024-12-11 18:16:38 +00:00
committed by GitHub
parent 47285b6207
commit 61c0a8b676
15 changed files with 52 additions and 64 deletions
+5 -6
View File
@@ -317,10 +317,9 @@ auto TokenizedBuffer::PrintToken(llvm::raw_ostream& output_stream,
auto TokenizedBuffer::FindLineIndex(int32_t byte_offset) const -> LineIndex {
CARBON_DCHECK(!line_infos_.empty());
const auto* line_it =
std::partition_point(line_infos_.begin(), line_infos_.end(),
[byte_offset](LineInfo line_info) {
return line_info.start <= byte_offset;
});
llvm::partition_point(line_infos_, [byte_offset](LineInfo line_info) {
return line_info.start <= byte_offset;
});
--line_it;
// If this isn't the first line but it starts past the end of the source, then
@@ -386,8 +385,8 @@ auto TokenizedBuffer::SourceBufferDiagnosticConverter::ConvertLoc(
int32_t offset = loc - buffer_->source_->text().begin();
// Find the first line starting after the given location.
const auto* next_line_it = std::partition_point(
buffer_->line_infos_.begin(), buffer_->line_infos_.end(),
const auto* next_line_it = llvm::partition_point(
buffer_->line_infos_,
[offset](const LineInfo& line) { return line.start <= offset; });
// Step back one line to find the line containing the given position.