From 068af3d9d4d7fd8f442ec365d3c9f6a3c02c64a7 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 28 Feb 2024 19:05:45 +1100 Subject: [PATCH] Use std::find when detecting end of line format --- src/buffer_utils.cc | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/buffer_utils.cc b/src/buffer_utils.cc index effb7cc74..76910483a 100644 --- a/src/buffer_utils.cc +++ b/src/buffer_utils.cc @@ -132,13 +132,9 @@ decltype(auto) parse_file(StringView filename, Func&& func) } bool has_crlf = false, has_lf = false; - for (auto it = pos; it != end; ++it) - { - if (*it == '\n') - ((it != pos and *(it-1) == '\r') ? has_crlf : has_lf) = true; - } - const bool crlf = has_crlf and not has_lf; - auto eolformat = crlf ? EolFormat::Crlf : EolFormat::Lf; + for (auto it = std::find(pos, end, '\n'); it != end; it = std::find(it+1, end, '\n')) + ((it != pos and *(it-1) == '\r') ? has_crlf : has_lf) = true; + auto eolformat = (has_crlf and not has_lf) ? EolFormat::Crlf : EolFormat::Lf; FsStatus fs_status{file.st.st_mtim, file.st.st_size, murmur3(file.data, file.st.st_size)}; return func(parse_lines(pos, end, eolformat), bom, eolformat, fs_status);