From f071556171c6ee8e46fd63c8c7f40b821791567b Mon Sep 17 00:00:00 2001 From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Wed, 7 Sep 2022 08:52:02 -0400 Subject: [PATCH 1/4] Clean up validation We can use ranges::is_sorted and ranges::binary_search and pass the checked extensions instead of passing the iterators directly. --- tools/validate/validate.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tools/validate/validate.cpp b/tools/validate/validate.cpp index 6b04580856..b42cf97abb 100644 --- a/tools/validate/validate.cpp +++ b/tools/validate/validate.cpp @@ -19,15 +19,16 @@ constexpr size_t max_line_length = 120; class BinaryFile { public: - explicit BinaryFile(const filesystem::path& filepath) { - m_file = _wfopen(filepath.c_str(), L"rb"); - + explicit BinaryFile(const filesystem::path& filepath) + // clang-format off + : m_file(_wfopen(filepath.c_str(), L"rb")) { + // clang-format on if (!m_file) { fwprintf(stderr, L"Validation failed: %ls couldn't be opened.\n", filepath.c_str()); } } - [[nodiscard]] bool read_next_block(vector& buffer) { + [[nodiscard]] bool read_next_block(vector& buffer) const { constexpr size_t BlockSize = 65536; buffer.resize(BlockSize); @@ -191,9 +192,9 @@ void scan_file( L".py"sv, L".yml"sv, }; - static_assert(is_sorted(checked_extensions.begin(), checked_extensions.end())); + static_assert(ranges::is_sorted(checked_extensions)); - if (binary_search(checked_extensions.begin(), checked_extensions.end(), filepath.extension().wstring())) { + if (ranges::binary_search(checked_extensions, filepath.extension().wstring())) { validation_failure(any_errors, filepath, L"file contains %zu lines with more than %zu columns.\n", overlength_lines, max_line_length); } @@ -229,10 +230,10 @@ int main() { L".gitmodules"sv, }; - static_assert(is_sorted(skipped_directories.begin(), skipped_directories.end())); - static_assert(is_sorted(skipped_extensions.begin(), skipped_extensions.end())); - static_assert(is_sorted(bad_extensions.begin(), bad_extensions.end())); - static_assert(is_sorted(tabby_filenames.begin(), tabby_filenames.end())); + static_assert(ranges::is_sorted(skipped_directories)); + static_assert(ranges::is_sorted(skipped_extensions)); + static_assert(ranges::is_sorted(bad_extensions)); + static_assert(ranges::is_sorted(tabby_filenames)); vector buffer; // reused for performance bool any_errors = false; @@ -244,7 +245,7 @@ int main() { if (!rdi->is_regular_file()) { if (rdi->is_directory()) { - if (binary_search(skipped_directories.begin(), skipped_directories.end(), filename)) { + if (ranges::binary_search(skipped_directories, filename)) { rdi.disable_recursion_pending(); } } @@ -266,18 +267,17 @@ int main() { const wstring extension = filepath.extension().wstring(); - if (binary_search(skipped_extensions.begin(), skipped_extensions.end(), extension)) { + if (ranges::binary_search(skipped_extensions, extension)) { continue; } - if (binary_search(bad_extensions.begin(), bad_extensions.end(), extension)) { + if (ranges::binary_search(bad_extensions, extension)) { validation_failure(any_errors, filepath, L"file should not be checked in."); continue; } - const TabPolicy tab_policy = binary_search(tabby_filenames.begin(), tabby_filenames.end(), filename) - ? TabPolicy::Allowed - : TabPolicy::Forbidden; + const TabPolicy tab_policy = + ranges::binary_search(tabby_filenames, filename) ? TabPolicy::Allowed : TabPolicy::Forbidden; scan_file(any_errors, filepath, tab_policy, buffer); } From 44757918e2f8c1198ba1336bedb599698185e00b Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Wed, 7 Sep 2022 15:39:49 -0700 Subject: [PATCH 2/4] Use an empty comment to force line wrapping. --- tools/validate/validate.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/validate/validate.cpp b/tools/validate/validate.cpp index b42cf97abb..efebe3a1c7 100644 --- a/tools/validate/validate.cpp +++ b/tools/validate/validate.cpp @@ -19,10 +19,8 @@ constexpr size_t max_line_length = 120; class BinaryFile { public: - explicit BinaryFile(const filesystem::path& filepath) - // clang-format off - : m_file(_wfopen(filepath.c_str(), L"rb")) { - // clang-format on + explicit BinaryFile(const filesystem::path& filepath) // + : m_file(_wfopen(filepath.c_str(), L"rb")) { if (!m_file) { fwprintf(stderr, L"Validation failed: %ls couldn't be opened.\n", filepath.c_str()); } From f7ca86c7f9b378459bcadc9841c78bfcfb10e512 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Mon, 12 Sep 2022 14:27:58 -0700 Subject: [PATCH 3/4] read_next_block() isn't conceptually const. --- tools/validate/validate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/validate/validate.cpp b/tools/validate/validate.cpp index efebe3a1c7..f884ac1199 100644 --- a/tools/validate/validate.cpp +++ b/tools/validate/validate.cpp @@ -26,7 +26,7 @@ class BinaryFile { } } - [[nodiscard]] bool read_next_block(vector& buffer) const { + [[nodiscard]] bool read_next_block(vector& buffer) { constexpr size_t BlockSize = 65536; buffer.resize(BlockSize); From cd3901a054e4a35cd7438dd90f81ff4ae83c463b Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Mon, 12 Sep 2022 15:47:42 -0700 Subject: [PATCH 4/4] Remove novel clang-format override --- tools/validate/validate.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/validate/validate.cpp b/tools/validate/validate.cpp index f884ac1199..9b562ec6b0 100644 --- a/tools/validate/validate.cpp +++ b/tools/validate/validate.cpp @@ -19,8 +19,7 @@ constexpr size_t max_line_length = 120; class BinaryFile { public: - explicit BinaryFile(const filesystem::path& filepath) // - : m_file(_wfopen(filepath.c_str(), L"rb")) { + explicit BinaryFile(const filesystem::path& filepath) : m_file(_wfopen(filepath.c_str(), L"rb")) { if (!m_file) { fwprintf(stderr, L"Validation failed: %ls couldn't be opened.\n", filepath.c_str()); }